zvariant

Trait NoneValue

Source
pub trait NoneValue {
    type NoneType;

    // Required method
    fn null_value() -> Self::NoneType;
}
Expand description

Type that uses a special value to be used as none.

See Optional documentation for the rationale for this trait’s existence.

§Caveats

Since use of default values as none is typical, this trait is implemented for all types that implement Default for convenience. Unfortunately, this means you can not implement this trait manually for types that implement Default.

Moreoever, since bool implements Default, NoneValue gets implemented for bool as well. However, this is unsound since its not possible to distinguish between false and None in this case. This is why you’ll get a panic on trying to serialize or deserialize an Optionanl<bool>.

Required Associated Types§

Required Methods§

Source

fn null_value() -> Self::NoneType

The none-equivalent value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> NoneValue for T
where T: Default,