kernel icon indicating copy to clipboard operation
kernel copied to clipboard

Refactor to use TryFrom

Open hawkw opened this issue 8 years ago • 4 comments

Since the TryFrom trait is in unstable Rust (rust-lang/rust#33417), we should rewrite a lot of failable conversions into TryFrom implementations. For example, a lot of the ELF parsing code that returns Result<Self, ElfError> can probably be rewritten to use TryFrom.

Where removing existing failable conversion methods would break a lot of other code, we can temporarily preserve the existing API by having it wrap a try_from call, and phase it out gradually.

We don't have to worry about TryFrom not being on stable, since we can't build SOS on stable anyway.

hawkw avatar Mar 10 '17 16:03 hawkw

I'm marking this as "easy" since it is a reasonably simple refactoring that doesn't require a great deal of OS knowledge.

hawkw avatar Mar 10 '17 16:03 hawkw

As an update to the issue the above RFC was implemented and merged with PR : https://github.com/rust-lang/rust/pull/49305 . It caused notable breakages in the ecosystem and got reverted : https://github.com/rust-lang/rust/pull/49518

tirkarthi avatar Apr 02 '18 10:04 tirkarthi

@tirkarthi my understanding is that all that was reverted is the addition of TryFrom to the prelude, the traits are still stabilized, correct?

hawkw avatar Apr 02 '18 20:04 hawkw

Yes, the team is looking for a way to introduce this with less breakages.

tirkarthi avatar Apr 02 '18 22:04 tirkarthi