Skip to main content

IndexInt

Trait IndexInt 

Source
pub trait IndexInt:
    Copy
    + Send
    + Sync
    + 'static {
    // Required method
    fn to_usize(self) -> usize;
}
Expand description

Trait for index element types.

All indices within a single CachedFunction must use the same integer type. Implemented for u8, u16, u32, and usize. Use u8 for quantics TCI where local_dim = 2.

§Examples

use tensor4all_tcicore::{IndexInt, CachedFunction};

// Using u8 indices for quantics (local_dim = 2)
let cf = CachedFunction::new(
    |idx: &[u8]| idx.iter().map(|&x| x as usize).sum::<usize>(),
    &[2, 2, 2],
).unwrap();
assert_eq!(cf.eval(&[1u8, 0, 1]), 2);

Required Methods§

Source

fn to_usize(self) -> usize

Convert this index element to usize.

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 IndexInt for u8

Source§

impl IndexInt for u16

Source§

impl IndexInt for u32

Source§

impl IndexInt for usize

Implementors§