Skip to main content

AsIndex

Trait AsIndex 

Source
pub trait AsIndex:
    Sized
    + Debug
    + Copy {
    // Required method
    fn as_index(self) -> isize;

    // Provided methods
    fn expect_elem_index(self, size: usize) -> usize { ... }
    fn expect_dim_index(self, size: usize) -> usize { ... }
}
Expand description

Helper trait for implementing indexing with support for negative indices.

§Example

use burn_std::AsIndex;

fn example<I: AsIndex, const D: usize>(dim: I, size: usize) -> isize {
   let dim: usize = dim.expect_dim_index(D);
   unimplemented!()
}

Required Methods§

Source

fn as_index(self) -> isize

Converts into an isize index.

Provided Methods§

Source

fn expect_elem_index(self, size: usize) -> usize

Short-form [IndexWrap::expect_index(idx, size)].

Source

fn expect_dim_index(self, size: usize) -> usize

Short-form [IndexWrap::expect_dim(idx, size)].

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 AsIndex for i8

Source§

impl AsIndex for i16

Source§

impl AsIndex for i32

Source§

impl AsIndex for i64

Source§

impl AsIndex for isize

Source§

impl AsIndex for u8

Source§

impl AsIndex for u16

Source§

impl AsIndex for u32

Source§

impl AsIndex for u64

Source§

impl AsIndex for usize

Source§

impl<T> AsIndex for &T
where T: AsIndex,

Implementors§