Artem-Romanenia / o2o

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

Question: how to provide a default value on flattened children #12

Closed SteelAlloy closed 5 months ago

SteelAlloy commented 5 months ago

Hi, great library

How can I provide a default value on flattened children ?

In this example, i want to provide a default value for foo.

use o2o::o2o;

struct Car {
    number_of_doors: i8,
    vehicle: Vehicle
}
struct Vehicle {
    number_of_seats: i16,
    foo: i16,
    machine: Machine,
}
struct Machine {
    brand: String,
    year: i16
}

#[derive(o2o)]
#[owned_into(Car)]
#[children(vehicle: Vehicle, vehicle.machine: Machine)]
struct CarDto {
    number_of_doors: i8,

    #[child(vehicle)]
    number_of_seats: i16,

    #[child(vehicle.machine)]
    brand: String,

    #[child(vehicle.machine)]
    year: i16
}

The following doesn't work :

#[ghosts(vehicle.foo: {42})]
                    ^ expected `@`

Thanks

Artem-Romanenia commented 5 months ago

Hi, thank you for such a high evaluation! You were almost there) The syntax is #[ghosts(child.path@field_name)], so in your case #[ghosts(vehicle@foo: {42})]. Please let me know if you have any other questions!