CTOffset

Trait CTOffset 

Source
pub trait CTOffset<Target> {
    type Offset: Unsigned + Add<U1>;

    // Required method
    fn offset() -> usize;
}
Expand description

Trait used to calculate the 0-indexed offset of a specific type item within compile time structures.

Cast the structure as CTOffset. If this trait is implemented, you can query the offset of the requested item from CTOffset::Offset. Alternatively a value can be constructed representing the offset, just call CTOffset::offset.

** Preferably use the CTOffsetExt trait! **

§Note

If the requested type cannot be found within the implemented structure, CTConsOffsetInvalid is returned.

§Example

let offset = <Cons<Cons<Cons<CTConsTerm, u8>, u32>, u64> as CTOffset<u64>>::offset();
assert_eq!(offset, 2);    // Note: Offset is 0-indexed!

Required Associated Types§

Source

type Offset: Unsigned + Add<U1>

The offset representation of the type Target within the implemented compile time structure.

§Note

If the type was NOT found within the implemented ct structure, CTConsOffsetInvalid is provided.

Required Methods§

Source

fn offset() -> usize

Returns a value representing the offset within the compile time structure.

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<Target> CTOffset<Target> for CTConsTerm

Source§

impl<Target, Tail, Head> CTOffset<Target> for Cons<Tail, Head>
where Tail: CTCons + CTOffset<Target> + CTCounter,

Source§

type Offset = <IfCheck<Head> as CTIfOffset<Target, <Tail as CTCounter>::Counter, <Tail as CTOffset<Target>>::Offset>>::Path