rune icon indicating copy to clipboard operation
rune copied to clipboard

Unwrap on Option is hard to use (moves value)

Open VorpalBlade opened this issue 1 year ago • 1 comments

Lets say you have something like this:

if system.is_server() {
    // I know fully qualified domain name is always set for servers, just unwrap it
    let fdqn = system.fdqn.unwrap();
}

// Later, in another file or function, configuring a different service:

if system.is_server() {
    // I know fully qualified domain name is always set for servers, just unwrap it
    let fdqn = system.fdqn.unwrap();
}

This doesn't work, since the first .unwrap() consumes the Option. Option also doesn't implement .clone() so there isn't even a workaround for this. Nor can I use .as_ref() like I could in Rust.

What is the suggested solution (in 0.13 preferably)?

VorpalBlade avatar Aug 11 '24 20:08 VorpalBlade

Not intended behavior. Containers shouldn't move values as they are being accessed.

udoprog avatar Aug 12 '24 06:08 udoprog