Messages in this thread |  | | Date | Wed, 01 Apr 2026 13:32:15 +0900 | | Subject | Re: [PATCH v5 0/4] rust: add `TryFrom` and `Into` derive macros | | From | "Alexandre Courbot" <> |
| |
Hi Jesung,
On Fri Mar 20, 2026 at 7:04 PM JST, Jesung Yang wrote: > Apologies for the delay.
Same. :)
> > On Sat Feb 28, 2026 at 2:31 PM KST, Alexandre Courbot wrote: > [...] >> FWIW I have converted nova-core to use this, and this results in -200LoC >> delta. Obviously I like this very much. :) >> >> A few pieces of feedback for things I noticed while doing the >> conversion: >> >> - Very often we need to convert a type from and into the same primitive. >> Not having to repeat the same thing in `#[try_from(foo)]` and >> `#[into(foo)]` for these cases would be nice. > > I think I can add a common attribute that works for both `TryFrom` and > `Into`, e.g. `#[convert(foo)]`. > >> - In some rare cases, we want to convert an enum with 4 variants into >> e.g. a `Bounded<u8, 2>`. This can be done using a `From` >> implementation, and that's what the register macro expects. These >> cases are not covered by the current macro (they are few however). > > I think you can just do the following?: > > #[derive(Into)] > #[into(Bounded<u8, 2>)] > enum Enum { > A, > B, > C, > D, > } > > let a = Bounded::<u8, 2>::from(Enum::A); > // or let a: Bounded<u8, 2> = Enum::A.into(); > > This works because `Into` actually generates the `From<Enum>` > implementation for `Bounded<u8, 2>`.
Sorry, I said the opposite of what I meant - we want to convert a `Bounded<u8, 2>` into an enum with 4 variants using a `From` implementation.
|  |