Derive Macro leer::Empty

source ·
#[derive(Empty)]
Expand description

Derive macro for Empty.

This can only be derived for structs. All struct fields need to implement Empty in order for the derive to work. If your struct has generic parameters, they won’t be bounded with Empty in the generated impl block. This is useful most of the time, because things like Vec<T> and Option<T> don’t require T: Empty to implement Empty. But this means that you sometimes have to add a global Empty bound to your parameter or implement Empty manually.

Examples

use leer::Empty;

#[derive(Empty)]
struct Zoo {
    foxes: Vec<Fox>,
    elephants: Vec<Elephant>,
}

struct Fox;
struct Elephant;


let empty_zoo = Zoo::empty();
use leer::Empty;

#[derive(Empty)]
struct MyStruct {
    a: Vec<u32>,        // => `vec![]`
    b: Option<String>,  // => `None`
    c: (),              // => `()`
}