AsIndex

Trait AsIndex 

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§

fn as_index(self) -> isize

Converts into an isize index.

Provided Methods§

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

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

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§

§

impl AsIndex for i8

§

fn as_index(self) -> isize

§

impl AsIndex for i16

§

fn as_index(self) -> isize

§

impl AsIndex for i32

§

fn as_index(self) -> isize

§

impl AsIndex for i64

§

fn as_index(self) -> isize

§

impl AsIndex for isize

§

fn as_index(self) -> isize

§

impl AsIndex for u8

§

fn as_index(self) -> isize

§

impl AsIndex for u16

§

fn as_index(self) -> isize

§

impl AsIndex for u32

§

fn as_index(self) -> isize

§

impl AsIndex for u64

§

fn as_index(self) -> isize

§

impl AsIndex for usize

§

fn as_index(self) -> isize

§

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

§

fn as_index(self) -> isize

Implementors§