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

Deduplicate Proto associated type in {From,TryFrom,Into}Proto #420

Closed
benluelo opened this issue Aug 4, 2023 · 0 comments · Fixed by #424
Closed

Deduplicate Proto associated type in {From,TryFrom,Into}Proto #420

benluelo opened this issue Aug 4, 2023 · 0 comments · Fixed by #424
Assignees

Comments

@benluelo
Copy link
Contributor

benluelo commented Aug 4, 2023

Currently, {From,TryFrom,Into}Proto each define their own associated type Proto, which is (silently) expected to be the same for Into and [Try]From. This is a relic of early prototyping that made it easier to rapidly iterate (as implementing Into didn't require implementing [Try]From, etc).

  • Define one trait Proto that defines an associated type Proto
    • Perhaps name the associated type Raw?
  • Add Proto as a supertrait of {From,TryFrom,Into}Proto
    • {From,TryFrom,Into}Proto will become convenience traits over {From,TryFrom,Into}<<Self as Proto>::Proto>

NOTE: Due to the never type still being unstable (:pensive:), FromProto and TryFromProto will remain as a way to differentiate fallible and infallible conversion (as opposed to putting everything in Proto). If Result::into_ok was stable, that could be used instead as a hypothetical Proto::Error type, but unfortunately it seems to be quite far away from stabilization. We could define an extension trait, but that results in rust-lang/rust#48919, which is annoying (and I'm not sure what else to call the method).

@benluelo benluelo self-assigned this Aug 4, 2023
benluelo added a commit that referenced this issue Aug 5, 2023
…424)

`{From,TryFrom,Into}Proto` no longer each define an associated type
`Proto`, instead there is a supertrait `Proto` and the aformentioned
traits are now a bounds alias/ convenience over `T: Proto +
{From,TryFrom,Into}<T::Proto>`.

closes #420 (nice 😎)
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 a pull request may close this issue.

1 participant