1
Fork 0

Update explanation of deref coercion

This commit is contained in:
Natalie Boehm 2017-08-07 13:56:20 -04:00 committed by GitHub
parent b298a58c78
commit 2a62b91343

View file

@ -163,11 +163,12 @@ use boxed::Box;
/// [`&str`]s as arguments unless they need a `String` for some specific /// [`&str`]s as arguments unless they need a `String` for some specific
/// reason. /// reason.
/// ///
/// In certain cases Rust doesn't have enough information to make this conversion, /// In certain cases Rust doesn't have enough information to make this
/// known as deref coercion. For example, in this case a string slice implements /// conversion, known as deref coercion. In the following example a string
/// a trait and the function takes anything that implements the trait, Rust would /// slice `&'a str` implements the trait `TraitExample`, and the function
/// need to make two implicit conversions which Rust doesn't know how to do. The /// `example_func` takes anything that implements the trait. In this case Rust
/// following example will not compile for that reason. /// would need to make two implicit conversions, which Rust doesn't have the
/// means to do. For that reason, the following example will not compile.
/// ///
/// ```compile_fail,E0277 /// ```compile_fail,E0277
/// trait TraitExample {} /// trait TraitExample {}
@ -182,9 +183,10 @@ use boxed::Box;
/// } /// }
/// ``` /// ```
/// ///
/// What would work in this case is changing the line `example_func(&example_string);` /// What would work in this case is changing the line
/// to `example_func(example_string.to_str());`. This works because we're doing the /// `example_func(&example_string);` to
/// conversion explicitly, rather than relying on the implicit conversion. /// `example_func(example_string.to_str());`. This works because we're doing
/// the conversion explicitly, rather than relying on the implicit conversion.
/// ///
/// # Representation /// # Representation
/// ///