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
warning: defining a method called `from_str` on this type; consider implementing the `std::str::FromStr` trait or choosing a less ambiguous name
--> src/lib.rs:222:5
|
222 | / pub fn from_str(s: &'a str) -> Result<JID<'a>> {
223 | | if s == "" {
224 | | return Err(Error::EmptyJID);
225 | | }
... |
305 | | JID::new(lpart, dpart.trim_right_matches('.'), rpart)
306 | | }
| |_____^
|
= note: #[warn(should_implement_trait)] on by default
= help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#should_implement_trait
For types that require an explicit type annotation, it is sometimes impossible to implement FromStr because its argument does not have a type annotation. For instance, consider the following:
use std::borrow;use std::str;structJID<'a>{local: borrow::Cow<'a,str>,}structDummyErr{}impl<'a> str::FromStrforJID<'a>{typeErr = DummyErr;fnfrom_str(s:&str) -> Result<Self,Self::Err>{// We can not guarantee that s lives longer than 'aOk(JID{local: s.into()})}}
Since we can never guarantee that the &str lives longer than 'a, FromStr cannot be implemented for this type.
Naming the method something else goes against the API guidelines (although admittedly it is confusing naming it the same thing as a method on a common trait).
For types that require an explicit type annotation, it is sometimes impossible to implement
FromStr
because its argument does not have a type annotation. For instance, consider the following:Since we can never guarantee that the &str lives longer than 'a, FromStr cannot be implemented for this type.
Naming the method something else goes against the API guidelines (although admittedly it is confusing naming it the same thing as a method on a common trait).
Related: #1600
The text was updated successfully, but these errors were encountered: