Expand description
Trait to abstract over types that have a notion of “being empty” and can
create such an empty instance. See Empty
. Intended to be a foundational
crate.
Examples
Using the trait:
use leer::Empty;
let v = String::empty();
Mostly useful for something like this:
use leer::Empty;
// Of course, in this specific case, `FromIterator` would be better. But
// you get the point.
fn one_two_three<C: Empty + Extend<u32>>() -> C {
let mut out = C::empty();
out.extend([1, 2, 3]);
out
}
let vec: Vec<_> = one_two_three();
let vec: std::collections::LinkedList<_> = one_two_three();
Crate features
derive
: if enabled, you can#[derive(Empty)]
for structs.
Traits
- Types that have a notion of “being empty” and can create such an empty instance.
Derive Macros
- Derive macro for
Empty
.