# just-convert
Easy conversion of structures
[](https://github.com/vettich/just-convert-rs)
[](https://crates.io/crates/just-convert)
[](https://docs.rs/just-convert)
# Example
```rust
#[derive(JustConvert, Default)]
#[convert(from_into(other::Mouse))]
#[convert(from_into(Cat, default))]
struct Dog {
#[convert(unwrap(from(Cat)))]
name: String,
#[convert(skip(from(other::Mouse)))]
#[convert(map(from(Cat, ". as i64"), into(Cat, ". as u64")))]
age: i64,
// inner of Option must be autoconvert
#[convert(skip(from_into(other::Mouse)))]
#[convert(map = ".map(Into::into)")]
error: Option,
}
#[derive(JustConvert, Default)]
struct Cat {
name: Option,
age: u64,
// inner of Option must be autoconvert
error: Option,
}
mod other {
pub struct Mouse {
pub name: String,
}
}
```
## Convert both sides at once
Specify the value for `from_into` as `#[convert(from_into(Struct))]`, instead of specifying `from` and `into` separately
```rust
#[derive(JustConvert)]
#[convert(from_into(some::B))]
struct A {
// ...
}
```
## Rename field
```rust
#[derive(JustConvert)]
#[convert(from_into(some::B))]
struct A {
#[convert(rename = user_id)]
id: String,
}
struct B {
user_id: String,
}
```
## Execute an arbitrary expression for the conversion
Use the `map` attribute to specify an arbitrary expression
To access the current field, use the dot character, for e.g., ".get_value()".
To access the current structure, use the `this` construct, e.g. "this.field.get_value()"
```rust
#[derive(JustConvert)]
#[convert(from(B))]
struct A {
// call any method of this field
#[convert(map = ".to_hex_string()")]
id: Uuid,
// casting (or "this.age as i64")
#[convert(map = ". as i64")]
age: i64,
// call any expression
#[convert(map = "format!(\"id: {}, age: {}\", this.id, this.age)")]
message: String,
}
struct B {
id: String,
age: u64,
}
```
## Auto convert types inside Option or Vec (and Option> and Vec