Skip to content

Commit

Permalink
small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem-Romanenia committed Sep 10, 2024
1 parent bb4afe5 commit 8099817
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 44 deletions.
37 changes: 0 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ And here's the code that `o2o` generates (from here on, generated code is produc
- [Type hints](#type-hints)
- [Lifetimes](#lifetimes)
- [Generics](#generics)
- [Generics both ways](#generics-both-ways)
- [Where clauses](#where-clauses)
- [Mapping to multiple structs](#mapping-to-multiple-structs)
- [Avoiding proc macro attribute name collisions (alternative instruction syntax)](#avoiding-proc-macro-attribute-name-collisions-alternative-instruction-syntax)
Expand Down Expand Up @@ -1568,42 +1567,6 @@ struct EntityDto {
```
</details>

### Generics both ways

```rust
use o2o::o2o;

struct Entity<T> {
something: T,
}

#[derive(o2o)]
#[map_owned(Entity<T>)]
struct EntityDto<T> {
something: T,
}
```
<details>
<summary>View generated code</summary>

``` rust ignore
impl<T> ::core::convert::From<Entity<T>> for EntityDto<T> {
fn from(value: Entity<T>) -> EntityDto<T> {
EntityDto {
something: value.something,
}
}
}
impl<T> ::core::convert::Into<Entity<T>> for EntityDto<T> {
fn into(self) -> Entity<T> {
Entity {
something: self.something,
}
}
}
```
</details>

### Where clauses

``` rust
Expand Down
14 changes: 7 additions & 7 deletions o2o-tests/tests/17_generic_path_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ struct Child<T> {
#[derive(o2o)]
#[o2o(
map(Parent::<i32>),
map(ParentModel::<i32>),
map(ParentModel<i32>),
into_existing(Parent::<i32>),
into_existing(ParentModel::<i32>),
into_existing(ParentModel<i32>),
)]
struct ParentDto {
parent_int: i32,
#[o2o(
from(Parent::<i32>| (&@.child).into()),
into(Parent::<i32>| child, (&@.diff_child).into()),
from(ParentModel::<i32>| (&@.child_diff).into()),
into(ParentModel::<i32>| child_diff, (&@.diff_child).into()),
from(ParentModel<i32>| (&@.child_diff).into()),
into(ParentModel<i32>| child_diff, (&@.diff_child).into()),
)]
diff_child: ChildDto,
}

#[derive(o2o)]
#[map(Child::<i32>)]
#[map(Child::<i16>)]
#[map(Child<i16>)]
struct ChildDto {
#[o2o(from(Child::<i32>| @.child_int as i16))]
#[o2o(into(Child::<i32>| @.child_int as i32))]
child_int: i16,
#[from(Child::<i32>| @.another_child_int as i8)]
#[into(Child::<i32>| another_child_int, @.diff_another_child_int as i32)]
#[from(Child::<i16>| @.another_child_int as i8)]
#[into(Child::<i16>| another_child_int, @.diff_another_child_int as i16)]
#[from(Child<i16>| @.another_child_int as i8)]
#[into(Child<i16>| another_child_int, @.diff_another_child_int as i16)]
diff_another_child_int: i8,
}

Expand Down

0 comments on commit 8099817

Please sign in to comment.