Skip to main content

Is

Trait Is 

Source
pub trait Is
where Self: Sealed + From<IsType<Self>> + Into<IsType<Self>> + AsRef<IsType<Self>> + AsMut<IsType<Self>>,
{ type Type; }
Expand description

Marker trait for type identity

This trait is used as part of the AnyKind trait pattern. It represents the concept of type identity, because all implementors have <Self as Is>::Type == Self. When used as a trait bound with a specific type, it guarantees that the corresponding type parameter is exactly the specific type. Stated differently, it guarantees that T == Specific in the following example.

where T: Is<Type = Specific>

Moreover, the super traits guarantee that any instance of or reference to a type T can be converted into the Specific type.

fn example<T>(mut any: T)
where
    T: Is<Type = Specific>,
{
    let specific_mut: &mut Specific = any.as_mut();
    let specific_ref: &Specific = any.as_ref();
    let specific: Specific = any.into();
}

Required Associated Types§

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> Is for T
where T: Sealed + AsRef<T> + AsMut<T>,

Source§

type Type = T