Artem-Romanenia / o2o

Object to Object mapper for Rust
Apache License 2.0
33 stars 2 forks source link

Question: How to map to wrapper types? #9

Closed PookieBuns closed 5 months ago

PookieBuns commented 5 months ago
#[derive(o2o)]
#[map(i32)]
struct MyWrapper(i32);

how would we map wrapper types?

Artem-Romanenia commented 5 months ago

If you actually need all 4 conversions, the best o2o has to offer is this:

#[derive(o2o::o2o)]
#[from_owned(i32| return MyWrapper(@))]
#[from_ref(i32| return MyWrapper(*@))]
#[into(i32| return @.0)]
struct MyWrapper(i32);

or this:

#[derive(o2o::o2o)]
#[from(i32)]
#[into(i32| return @.0)]
struct MyWrapper(#[from_owned(@)] #[from_ref(*@)] i32);

There used to be #[wrapped] attribute, which was doing the same thing but in much shorter form, but its implementation was bloating code base too much so I ditched it..

Artem-Romanenia commented 5 months ago

Closing this as resolved, please reopen or create a new one if you have some other questions