wokket / rust-hl7

Learning rust by playing with a HL7 parser. Use for real at your own risk!
18 stars 8 forks source link

Resolve clippy warning re: missing trait #14

Closed wokket closed 3 years ago

wokket commented 3 years ago

Currently Message is constructed ufing fn from_str(blah) which triggers the following warning in clippy:

warning: method `from_str` can be confused for the standard trait method `std::str::FromStr::from_str`
  --> src\message.rs:19:5
   |
19 | /     pub fn from_str(source: &'a str) -> Result<Self, Hl7ParseError> {
20 | |         //TODO: Try and get this as a std::str::FromStr impl  (lifetimes)
21 | |
22 | |         let delimiters = str::parse::<Separators>(source)?;
...  |
34 | |         Ok(msg)
35 | |     }
   | |_____^
   |
   = note: `#[warn(clippy::should_implement_trait)]` on by default
   = help: consider implementing the trait `std::str::FromStr` or choosing a less ambiguous method name
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait

Update Message to implement TryFrom<'a str> instead. Note that this will be a breaking API change but simple to resolve by ensuring std::convert::TryFrom is in scope, and replacing the from_str call with try_from.