Rust: Ref, Deref, Clone

To convert `Option<T>` to `Option<&T>` use `as_deref()`

To convert `&Option<T>` to `Option<&T>` use `as_deref()`

To convert `Option<&T>` to `Option<T>` use `cloned()`

I don't know what is the difference between `as_ref()` and `as_deref()` when it comes to converting `&Option<T>` to `Option<&T>`. 

 

 

This article was updated on December 21, 2020

Comments