Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwrap on Option is hard to use (moves value) #800

Open
VorpalBlade opened this issue Aug 11, 2024 · 1 comment
Open

Unwrap on Option is hard to use (moves value) #800

VorpalBlade opened this issue Aug 11, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@VorpalBlade
Copy link
Contributor

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)?

@udoprog udoprog added the bug Something isn't working label Aug 12, 2024
@udoprog
Copy link
Collaborator

udoprog commented Aug 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants