# Data Stream Derive
`data-stream-derive` provides procedural macros for (data-stream)[https://gitlab.com/porky11/data-stream]:
- `#[derive(ToStream)]`
- `#[derive(FromStream)]`
It generates stream serialization and deserialization code for structs and enums.
## Quick example
```rust
use data_stream::{FromStream, ToStream};
#[derive(ToStream, FromStream)]
struct SaveData {
id: u32,
name: String,
}
```
## Supported attributes
### Container attributes
`#[stream(bounds = "...")]`
```rust
use data_stream::{FromStream, ToStream};
use data_stream::collections::SizeSettings;
#[derive(ToStream, FromStream)]
#[stream(bounds = "SizeSettings")]
struct Wrapper<T> {
value: T,
}
```
### Field attributes
`#[field(ignore)]`
Ignored fields are not serialized and are filled with `Default::default()` on deserialize.
`#[field(order = N)]`
Controls read/write order of fields.
```rust
use data_stream::{FromStream, ToStream};
#[derive(ToStream, FromStream)]
struct Ordered {
#[field(order = 1)]
b: u32,
#[field(order = 0)]
a: u32,
#[field(ignore)]
cache: u32,
}
```
### Variant attributes
`#[variant(index = N)]`
Sets a fixed enum discriminant value.
```rust
use data_stream::{FromStream, ToStream};
#[derive(ToStream, FromStream)]
enum Message {
#[variant(index = 1)]
Ping,
#[variant(index = 2)]
Pong(u32),
}
```