• lseif@sopuli.xyz
    link
    fedilink
    arrow-up
    1
    ·
    11 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");