You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This compiles but I believe it is not using this version of map presented in the book, but rather it is using the one from the standard library. If you rename the function to z_map to distinguish them you get the following message:
<anon>:18:26: 18:54 error: no method named `z_map` found for type `core::option::Option<usize>` in the current scope
<anon>:18 find(file_name, '.').z_map(|i| &file_name[i+1..])
I believe that this an error in the book because the function presented does not use self, &self, or &mut self as the first parameter and thus cannot use dot syntax for calling map. However, it may be intended to call the real map function and not the one in the prior example. If that is the case I find this area confusing and would suggest that this is changed or clarified. I think changing the name of the example function would be sufficient personally.
Later in the same area of the book there is another similar example function:
fn unwrap_or<T>(option:Option<T>,default:T) -> T{
and then for the example following it, a note:
(Note that unwrap_or is defined as a method on Option in the standard library, so we use that here instead of the free-standing function we defined above.
That would be a great inclusion too.
The text was updated successfully, but these errors were encountered:
Under the heading "Composing Option values" in Section 5.7 of the Rust Programming Language at https://doc.rust-lang.org/book/error-handling.html, a function is defined:
A later example invokes appears to invoke this function:
This compiles but I believe it is not using this version of map presented in the book, but rather it is using the one from the standard library. If you rename the function to z_map to distinguish them you get the following message:
I believe that this an error in the book because the function presented does not use self, &self, or &mut self as the first parameter and thus cannot use dot syntax for calling map. However, it may be intended to call the real map function and not the one in the prior example. If that is the case I find this area confusing and would suggest that this is changed or clarified. I think changing the name of the example function would be sufficient personally.
Later in the same area of the book there is another similar example function:
and then for the example following it, a note:
(Note that unwrap_or is defined as a method on Option in the standard library, so we use that here instead of the free-standing function we defined above.
That would be a great inclusion too.
The text was updated successfully, but these errors were encountered: