Trait Cast

Source
pub trait Cast:
    AlignOf
    + AllBitPatternsValid
    + 'static
    + PartialEq
    + Debug
    + ToOwned {
    // Required methods
    fn default_ref() -> &'static Self;
    fn try_from_aligned_slice(
        slice: &AlignedSlice<Self::AlignOf>,
    ) -> Result<&Self, WrongSize>;
    fn try_from_aligned_slice_mut(
        slice: &mut AlignedSlice<Self::AlignOf>,
    ) -> Result<&mut Self, WrongSize>;

    // Provided method
    fn from_aligned_slice(slice: &AlignedSlice<Self::AlignOf>) -> &Self { ... }
}
Expand description

Trait implemented by all our types that have the same representation as the GVariant type

This allows casting appropriately aligned AlignedSlices to rust types.

Don’t implement this class for your own types. It’s already implemented for all appropriate types. It’s automatically implemented for Structure types generated by the gv! macro.

Required Methods§

Source

fn default_ref() -> &'static Self

Get a static reference to the default value for this type.

In GVariant every type has a default value which is used in certian circumstances in-lieu of returning errors during deserialisation. We’re always dealing with references so std::default::Default isn’t appropriate.

Source

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Provided Methods§

Source

fn from_aligned_slice(slice: &AlignedSlice<Self::AlignOf>) -> &Self

Cast slice to type Self.

This always succeeds. If the slice is the wrong size a defualt value is returned in accordance with the GVariant spec.

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.

Implementations on Foreign Types§

Source§

impl Cast for f64

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for i16

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for i32

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for i64

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for u8

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for u16

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for u32

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl Cast for u64

Source§

fn default_ref() -> &'static Self

Source§

fn try_from_aligned_slice( slice: &AlignedSlice<Self::AlignOf>, ) -> Result<&Self, WrongSize>

Source§

fn try_from_aligned_slice_mut( slice: &mut AlignedSlice<Self::AlignOf>, ) -> Result<&mut Self, WrongSize>

Source§

impl<'a, T: Cast + 'static + Copy> Cast for [T]

Implementors§