# Tuco
Tuco can automatically generate tuple representations of simple types. This is helpful if you want your API to expose convertible types. Down converting a struct to a tuple erases the struct field names resulting in an object which is up convertible to a struct with the similar field composition.
Using `#[derive(Tuco)]` Will automatically derive `Tuco` and generate a tuple representation of your struct and assign it to the associated type `Tuco::Tuple`
Tuco can be used in places where data serialization is used with some differences:
- Conversion operations are validated at compile time.
- Since tuples are unnamed, any matching tuple shape may be used to construct your type. No further integrity checks are applied at this time.
- Tuco does not automatically serialize your types to string data.
## Todo
- [x] Support structs with named fields
- [x] Support structs with unnamed fields
- [x] Support nested tuco
- [x] Support structs with generic types
- [x] Reduce single element structs into their inner type,
instead of using single element tuples.
- [x] Tests
- [ ] Documentation
- [ ] Compiler errors
## Example
```rust
fn tuco_equivalent() {
#[derive(Tuco)]
struct MyStruct {
a: i32,
b: String,
c: bool,
}
#[derive(Tuco)]
struct MyOtherStruct {
x: i32,
y: String,
z: bool,
}
}
```
```rust
#[derive(Tuco)]
struct MyNestedStruct {
x: i32,
#[tuco]
y: MyStruct,
z: bool,
}
#[derive(Tuco)]
struct MyOtherNestedStruct {
x: i32,
#[tuco]
y: MyOtherStruct,
z: bool,
}
fn nested_struct() {
let my_nested_struct = MyNestedStruct {
x: 10,
y: MyStruct {
a: 1,
b: "qwe".to_string(),
c: true,
},
z: false,
};
println!("{:?}", my_nested_struct);
let my_other_struct = MyOtherNestedStruct::from_tuco(my_nested_struct);
println!("{:?}", my_other_struct);
}
```
Output:
```
MyNestedStruct { x: 10, y: MyStruct { a: 1, b: "qwe", c: true }, z: false }
MyOtherNestedStruct { x: 10, y: MyOtherStruct { x: 1, y: "qwe", z: true }, z: false }
```