wispbit logo
wispbit
Early Access
  • Rules
    new!
  • Blog
  • Pricing
Categories
  • typescript
    22
  • postgresql
    15
  • migrations
    15
  • drizzle
    9
  • python
    8
  • nextjs
    8
  • react
    7
  • sqlalchemy
    6
  • alembic
    6
  • mysql
    4
  • markdown
    2
  • php
    2
  • rust
    2
  • javascript
    2
  • vue
    2
  • css
    1
  • expressjs
    1
  • flask
    1
  • quart
    1
  • golang
    1
  • graphql
    1

rust Rules

2 rules found for rust

Check character boundaries in Rust

When truncating strings, ensure you check character boundaries to prevent panics with multi-byte UTF-8 characters. Bad: `rust // This can cause a panic if truncation happens in the middle of a multi-byte character let mut value = some_string; value.truncate(limit); ` Good: `rust // Check character boundaries before truncating let mut value = some_string; let mut index = limit; while !value.is_char_boundary(index) { index -= 1; } value.truncate(index); `

rust

Prefer logging instead of panicking in Rust

Use logging instead of panicking for recoverable errors. For operations that might fail but don't compromise the entire application state, log the error and provide a fallback rather than panicking. Bad: `rust let top = editor.row_for_block(decorations.prompt_block_id, cx).unwrap(); let bottom = editor.row_for_block(decorations.end_block_id, cx).unwrap(); ` Good: `rust let scroll_target_range = maybe!({ let top = editor.row_for_block(decorations.prompt_block_id, cx)?.0 as f32; let bottom = editor.row_for_block(decorations.end_block_id, cx)?.0 as f32; Some((top, bottom)) }); if scroll_target_range.is_none() { log::error!("bug: failed to find blocks for scrolling to inline assist"); } // Use a fallback value when the operation fails let scroll_target_range = scroll_target_range.unwrap_or_else(|| { // fallback calculation }); `

rust

wispbit
Privacy policyTerms of serviceBook a demo