Skip to content

Make Option.unwrap documentation more precise #23713

Closed
@jviereck

Description

@jviereck

Reading the current documentation about Option<T>.unwrap() at

http://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap

it is not clear to me what the effect of unwrap() is. I was supposing calling this function returns the value stored in the Option type and replaces it by an None value. However, this seems not to be the case as the second assertion in the following example program passes fine:

fn main() {
    let 
    let x = Some("air");
    assert_eq!(x.unwrap(), "air");
    assert_eq!(x.is_some(), true);
}

(You can run the program online at http://goo.gl/F9OnFk).

In addition, the current documentation says:

Returns the inner T of a Some(T).

Does this means the value contained in the Some(T) is moved out or cloned or is a borrow taken? Also, T is a type and I don't think that the function really returns a type, but a value of type T. Therefore, should the quoted sentence maybe reworded towards something along the lines of:

Returns the value of type T as it is contained in the Some(T).

Please let me know what you think about these points. I am more than happy to provide a PR to improve the documentation, but I don't know all the answers to the questions I have raised above and I am also not sure if my claims are correct :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions