Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Summarizes Rust systems programming patterns: ownership and borrowing, traits, async runtimes, error handling, and unsafe code guidelines.
Use this skill ↓77% 82%+5 ptsof test cases passed
Passed 18 of 22 test cases with the skill, and 17 of 22 without it.
3 of 3 safety checks passed
Not used yet
fn process_data(data: &[u8]) -> Vec<u8> {
data.iter().map(|b| b.wrapping_add(1)).collect()
}
fn modify_in_place(data: &mut Vec<u8>) {
data.retain(|b| *b != 0);
data.sort_unstable();
}
fn take_ownership(data: Vec<u8>) -> Vec<u8> {
let mut result = data;
result.push(0xFF);
result
}
fn main() {
let data = vec![1, 2, 3, 0, 4];
let processed = process_data(&data); // borrow: data still usable
let mut owned = take_ownership(data); // move: data no longer usable
modify_in_place(&mut owned); // mutable borrow
}
Prefer borrowing (&T, &mut T) over ownership transfer. Use Clone only when necessary.
use thiserror::Error;
#[derive(Error, Debug)]
pub enum AppError {
#[error("database error: {0}")]
Database(#[from] sqlx::Error),
Skills that do similar work, with their benchmark result.
Next to this one in the catalogue, plus more from the same author.