Trait zvariant::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.

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

type NoneType = T