macro_rules! Unused {
($($type:ty $(: $variance:ident)?),+ $(,)?) => { ... };
}Expand description
A macro that allows for the creation of Unused type containers.
A basic example of usage can be found in the crate documentation.
§Usage
use unused::Unused;
struct Foo<A, B, C, D, E> {
unused: Unused!(
A,
B,
C: covariant,
D: contravariant,
E: invariant,
),
}
§Variances
You can have different
type variances when
working with Unused.
§Invariant
Invariance is the default:
let unused: Unused!(u8) = Unused;
// is the same as:
let unused: Unused!(u8: invariant) = Unused;§Covariance and Contravariance
To make Foo covariant over A and contravariant over B:
struct Foo<A, B> {
unused: Unused!(A: covariant, B: contravariant),
}§Lifetimes
Variance is particularily useful when it comes to lifetimes:
struct Foo<'foo> {
unused: Unused!(&'foo (): covariant),
}
fn change_foo_lifetime<'a>(foo: Foo<'static>) -> Foo<'a> {
foo
}