332
-Wall ain't all (lemmy.world)
submitted 11 months ago by qaz@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] lseif@sopuli.xyz 1 points 9 months ago

sometimes you need an unused variable. some uses in rust:

// destructuring
let (width, _height) = get_dimensions();

// trait implementations (i couldnt think of a better example for this)
impl Into for AlwaysZero {
    fn into(_value: Self) -> {
        return 0;
    }
}

// some types (eg. Result) must be 'used'
// assigned to a variable if we dont care about the return value
let _ = returns_result("foo");
this post was submitted on 13 Oct 2023
332 points (95.9% liked)

Programmer Humor

32048 readers
1609 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS