Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/from str #19

Closed

Conversation

sempervictus
Copy link
Contributor

Merges the parallel work we both started doing into a single implementation providing both by wrapping from with try_from to deliver raw and wrapped results.

RageLtMan added 2 commits August 8, 2021 12:27
Due to the lifetime tracking required for this library to work as
efficiently as it does, FromStr cannot be implemented as it doesn't
account for the internal str's lifetime. The closest approximation
so far is to implement From<&'a str> returning the Message<'a> to
the caller instead of producing a Result enum like `from_str()`.

Testing
  Added test to compare the structures created by `from(&str)` and
by `from_str(&str)` - passing.
@sempervictus
Copy link
Contributor Author

sempervictus commented Aug 8, 2021

Interesting, cargo test does not like the From and TryFrom - conflicts with Core, supposedly:

$ cargo test
   Compiling rust-hl7 v0.3.0 (/opt/code/Rust/rust-hl7)
error[E0119]: conflicting implementations of trait `std::convert::TryFrom<&str>` for type `message::Message<'_>`
   --> src/message.rs:113:1
    |
113 | impl<'a> TryFrom<&'a str> for Message<'a> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `core`:
            - impl<T, U> TryFrom<U> for T
              where U: Into<T>;

error[E0119]: conflicting implementations of trait `std::convert::TryFrom<&str>` for type `message::Message<'_>`
   --> src/message.rs:113:1
    |
113 | impl<'a> TryFrom<&'a str> for Message<'a> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `core`:
            - impl<T, U> std::convert::TryFrom<U> for T
              where U: Into<T>;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
error: could not compile `rust-hl7`

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
error: build failed

which seems to be this issue - looking into "specialization" (always fun to learn something new :) ).

@sempervictus
Copy link
Contributor Author

Confusing. The more specificity i add the more confusing the compiler errors get.
I guess we either have to choose from() or try_from() - thoughts?

@wokket wokket deleted the branch wokket:feat/14-try_from-impl August 8, 2021 20:32
@wokket wokket closed this Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants