Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix<T> { /* private fields */ }
Expand description

A 2D matrix with row-major storage

Data is stored in row-major format (C-style), where consecutive elements in memory belong to the same row. This is compatible with NumPy’s default layout and optimal for cache locality when accessing rows.

§Storage Layout

For a 2x3 matrix:

[[a, b, c],
 [d, e, f]]

Data is stored as: [a, b, c, d, e, f]

§Example

use trueno::Matrix;

let m = Matrix::from_vec(2, 2, vec![1.0, 2.0, 3.0, 4.0]).unwrap();
assert_eq!(m.get(0, 0), Some(&1.0));
assert_eq!(m.get(0, 1), Some(&2.0));
assert_eq!(m.get(1, 0), Some(&3.0));
assert_eq!(m.get(1, 1), Some(&4.0));

Implementations§

Source§

impl Matrix<f32>

Source

pub fn matmul(&self, other: &Matrix<f32>) -> Result<Matrix<f32>, TruenoError>

Matrix multiplication (matmul)

Computes C = A × B where A is m×n, B is n×p, and C is m×p.

§Arguments
  • other - The matrix to multiply with (right operand)
§Returns

A new matrix containing the result of matrix multiplication

§Errors

Returns InvalidInput if matrix dimensions are incompatible (i.e., self.cols != other.rows)

§Example
use trueno::Matrix;

let a = Matrix::from_vec(2, 2, vec![1.0, 2.0, 3.0, 4.0]).unwrap();
let b = Matrix::from_vec(2, 2, vec![5.0, 6.0, 7.0, 8.0]).unwrap();
let c = a.matmul(&b).unwrap();

// [[1, 2],   [[5, 6],   [[19, 22],
//  [3, 4]] ×  [7, 8]] =  [43, 50]]
assert_eq!(c.get(0, 0), Some(&19.0));
assert_eq!(c.get(0, 1), Some(&22.0));
assert_eq!(c.get(1, 0), Some(&43.0));
assert_eq!(c.get(1, 1), Some(&50.0));
Source

pub fn batched_matmul( a_data: &[f32], b_data: &[f32], batch: usize, m: usize, k: usize, n: usize, ) -> Result<Vec<f32>, TruenoError>

Batched matrix multiplication for 3D tensors.

Computes [batch, m, k] @ [batch, k, n] -> [batch, m, n] using SIMD for each batch.

Source

pub fn batched_matmul_4d( a_data: &[f32], b_data: &[f32], batch: usize, heads: usize, m: usize, k: usize, n: usize, ) -> Result<Vec<f32>, TruenoError>

Batched matrix multiplication for 4D tensors (attention pattern).

Computes [batch, heads, m, k] @ [batch, heads, k, n] -> [batch, heads, m, n]

Source§

impl Matrix<f32>

Source

pub fn transpose(&self) -> Matrix<f32>

Transpose this matrix (swap rows and columns)

Returns a new matrix with dimensions swapped: self.rows → result.cols, self.cols → result.rows.

§Performance

Uses cache-optimized block-wise transpose with 32x32 blocks. Sequential writes for output ensure good cache behavior.

§Example
use trueno::Matrix;

let m = Matrix::from_vec(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).unwrap();
let t = m.transpose();

// [[1, 2, 3],     [[1, 4],
//  [4, 5, 6]]  →   [2, 5],
//                  [3, 6]]
assert_eq!(t.rows(), 3);
assert_eq!(t.cols(), 2);
assert_eq!(t.get(0, 0), Some(&1.0));
assert_eq!(t.get(0, 1), Some(&4.0));
assert_eq!(t.get(1, 0), Some(&2.0));
Source

pub fn matvec(&self, v: &Vector<f32>) -> Result<Vector<f32>, TruenoError>

Matrix-vector multiplication (column vector): A × v

Multiplies this matrix by a column vector, computing A × v where the result is a column vector with length equal to the number of rows in A.

§Mathematical Definition

For an m×n matrix A and an n-dimensional vector v:

result[i] = Σ(j=0 to n-1) A[i,j] × v[j]
§Arguments
  • v - Column vector with length equal to self.cols()
§Returns

A new vector with length self.rows()

§Errors

Returns InvalidInput if v.len() != self.cols()

§Example
use trueno::{Matrix, Vector};

let m = Matrix::from_vec(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).unwrap();
let v = Vector::from_slice(&[1.0, 2.0, 3.0]);
let result = m.matvec(&v).unwrap();

// [[1, 2, 3]   [1]   [1×1 + 2×2 + 3×3]   [14]
//  [4, 5, 6]] × [2] = [4×1 + 5×2 + 6×3] = [32]
//               [3]
assert_eq!(result.as_slice(), &[14.0, 32.0]);
Source

pub fn vecmat( v: &Vector<f32>, m: &Matrix<f32>, ) -> Result<Vector<f32>, TruenoError>

Vector-matrix multiplication (row vector): v^T × A

Multiplies a row vector by this matrix, computing v^T × A where the result is a row vector with length equal to the number of columns in A.

§Mathematical Definition

For an m-dimensional vector v and an m×n matrix A:

result[j] = Σ(i=0 to m-1) v[i] × A[i,j]
§Arguments
  • v - Row vector with length equal to m.rows()
  • m - Matrix to multiply
§Returns

A new vector with length m.cols()

§Errors

Returns InvalidInput if v.len() != m.rows()

§Example
use trueno::{Matrix, Vector};

let m = Matrix::from_vec(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).unwrap();
let v = Vector::from_slice(&[1.0, 2.0]);
let result = Matrix::vecmat(&v, &m).unwrap();

// [1, 2] × [[1, 2, 3]  = [1×1 + 2×4, 1×2 + 2×5, 1×3 + 2×6]
//           [4, 5, 6]]
//         = [9, 12, 15]
assert_eq!(result.as_slice(), &[9.0, 12.0, 15.0]);
Source§

impl Matrix<f32>

Source

pub fn convolve2d( &self, kernel: &Matrix<f32>, ) -> Result<Matrix<f32>, TruenoError>

Perform 2D convolution with a kernel

Applies a 2D convolution operation using “valid” padding (no padding), resulting in an output smaller than the input.

§Arguments
  • kernel - Convolution kernel (filter) to apply
§Returns

Convolved matrix with dimensions:

  • rows: input.rows - kernel.rows + 1
  • cols: input.cols - kernel.cols + 1
§Errors

Returns InvalidInput if:

  • Kernel is larger than input in any dimension
§Example
use trueno::Matrix;

// 5x5 input image
let input = Matrix::from_vec(
    5, 5,
    vec![
        0.0, 0.0, 0.0, 0.0, 0.0,
        0.0, 0.0, 0.0, 0.0, 0.0,
        0.0, 0.0, 9.0, 0.0, 0.0,
        0.0, 0.0, 0.0, 0.0, 0.0,
        0.0, 0.0, 0.0, 0.0, 0.0,
    ]
)?;

// 3x3 averaging kernel
let kernel_val = 1.0 / 9.0;
let kernel = Matrix::from_vec(
    3, 3,
    vec![kernel_val; 9]
)?;

let result = input.convolve2d(&kernel)?;
assert_eq!(result.rows(), 3); // 5 - 3 + 1
assert_eq!(result.cols(), 3);
Source§

impl Matrix<f32>

Source

pub fn max_pool2d( &self, kernel: (usize, usize), stride: (usize, usize), ) -> Result<Matrix<f32>, TruenoError>

2D Max Pooling operation for CNN downsampling

Applies max pooling over a 2D input tensor with specified kernel size and stride.

§Arguments
  • kernel - (kernel_height, kernel_width) pooling window size
  • stride - (stride_height, stride_width) step size
§Examples
use trueno::matrix::Matrix;
let input = Matrix::from_vec(4, 4, vec![
    1.0, 2.0, 3.0, 4.0,
    5.0, 6.0, 7.0, 8.0,
    9.0, 10.0, 11.0, 12.0,
    13.0, 14.0, 15.0, 16.0,
])?;
let pooled = input.max_pool2d((2, 2), (2, 2))?;
assert_eq!(pooled.shape(), (2, 2));
assert_eq!(pooled.get(0, 0), Some(&6.0));  // max of [1,2,5,6]
assert_eq!(pooled.get(1, 1), Some(&16.0)); // max of [11,12,15,16]
Source

pub fn avg_pool2d( &self, kernel: (usize, usize), stride: (usize, usize), ) -> Result<Matrix<f32>, TruenoError>

2D Average Pooling operation for CNN downsampling

Applies average pooling over a 2D input tensor with specified kernel size and stride.

§Arguments
  • kernel - (kernel_height, kernel_width) pooling window size
  • stride - (stride_height, stride_width) step size
§Examples
use trueno::matrix::Matrix;
let input = Matrix::from_vec(4, 4, vec![
    1.0, 2.0, 3.0, 4.0,
    5.0, 6.0, 7.0, 8.0,
    9.0, 10.0, 11.0, 12.0,
    13.0, 14.0, 15.0, 16.0,
])?;
let pooled = input.avg_pool2d((2, 2), (2, 2))?;
assert_eq!(pooled.shape(), (2, 2));
assert!((pooled.get(0, 0).unwrap_or(&0.0) - 3.5).abs() < 1e-5);  // avg of [1,2,5,6]
Source§

impl Matrix<f32>

Source

pub fn embedding_lookup( &self, indices: &[usize], ) -> Result<Matrix<f32>, TruenoError>

Lookup embeddings by indices

Performs embedding lookup where self is the embedding table with shape [vocab_size, embed_dim] and indices specify which rows to select.

§Arguments
  • indices - Slice of indices into the embedding table
§Returns

A matrix with shape [indices.len(), embed_dim] containing the selected rows

§Errors

Returns InvalidInput if any index is out of bounds

§Example
use trueno::Matrix;

// Create embedding table: 4 words, 3-dimensional embeddings
let embeddings = Matrix::from_vec(4, 3, vec![
    1.0, 2.0, 3.0,   // word 0
    4.0, 5.0, 6.0,   // word 1
    7.0, 8.0, 9.0,   // word 2
    10.0, 11.0, 12.0 // word 3
])?;

// Lookup embeddings for indices [1, 3, 0]
let result = embeddings.embedding_lookup(&[1, 3, 0])?;

assert_eq!(result.rows(), 3);
assert_eq!(result.cols(), 3);
assert_eq!(result.get(0, 0), Some(&4.0)); // word 1
assert_eq!(result.get(1, 0), Some(&10.0)); // word 3
assert_eq!(result.get(2, 0), Some(&1.0)); // word 0
Source

pub fn embedding_lookup_sparse( &self, indices: &[usize], ) -> Result<(Matrix<f32>, Vec<usize>), TruenoError>

Lookup embeddings with gradient tracking support (for training)

Returns both the embeddings and a sparse gradient accumulator. This is useful for sparse gradient updates in training.

§Arguments
  • indices - Slice of indices into the embedding table
§Returns

Tuple of (embeddings, unique_indices) where unique_indices can be used for sparse gradient updates

§Errors

Returns InvalidInput if any index is out of bounds

Source

pub fn topk(&self, k: usize) -> Result<(Vec<f32>, Vec<usize>), TruenoError>

Top-K selection: returns the k largest elements and their indices

Useful for beam search, sampling, and ranking operations. Searches row-major order and returns (values, indices) sorted descending.

§Examples
use trueno::matrix::Matrix;
let m = Matrix::from_vec(2, 3, vec![1.0, 5.0, 3.0, 2.0, 6.0, 4.0])?;
let (values, indices) = m.topk(2)?;
assert_eq!(values, vec![6.0, 5.0]);
assert_eq!(indices, vec![4, 1]);  // flat indices
Source

pub fn gather( &self, indices: &[usize], axis: usize, ) -> Result<Matrix<f32>, TruenoError>

Gather elements along axis using indices

For 2D matrix with axis=0: output[i] = self[indices[i], :] For 2D matrix with axis=1: output[:, i] = self[:, indices[i]]

§Examples
use trueno::matrix::Matrix;
let m = Matrix::from_vec(3, 2, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0]).unwrap();
let gathered = m.gather(&[2, 0], 0).unwrap();  // Select rows 2 and 0
assert_eq!(gathered.shape(), (2, 2));
assert_eq!(gathered.get(0, 0), Some(&5.0));  // Row 2
assert_eq!(gathered.get(1, 0), Some(&1.0));  // Row 0
Source

pub fn pad( &self, padding: ((usize, usize), (usize, usize)), value: f32, ) -> Result<Matrix<f32>, TruenoError>

Pad matrix with a constant value

§Arguments
  • padding - ((top, bottom), (left, right)) padding amounts
  • value - constant value to pad with (usually 0.0)
§Examples
use trueno::matrix::Matrix;
let m = Matrix::from_vec(2, 2, vec![1.0, 2.0, 3.0, 4.0]).unwrap();
let padded = m.pad(((1, 1), (1, 1)), 0.0).unwrap();
assert_eq!(padded.shape(), (4, 4));
assert_eq!(padded.get(0, 0), Some(&0.0));  // top-left padding
assert_eq!(padded.get(1, 1), Some(&1.0));  // original (0,0)
Source§

impl Matrix<f32>

Source

pub fn new(rows: usize, cols: usize) -> Self

Creates a new matrix with uninitialized values

§Arguments
  • rows - Number of rows
  • cols - Number of columns
§Returns

A new matrix with dimensions rows x cols containing uninitialized values

§Example
use trueno::Matrix;

let m = Matrix::new(3, 4);
assert_eq!(m.rows(), 3);
assert_eq!(m.cols(), 4);
Source

pub fn from_vec( rows: usize, cols: usize, data: Vec<f32>, ) -> Result<Self, TruenoError>

Creates a matrix from a vector of data

§Arguments
  • rows - Number of rows
  • cols - Number of columns
  • data - Vector containing matrix elements in row-major order
§Errors

Returns InvalidInput if data.len() != rows * cols

§Example
use trueno::Matrix;

let m = Matrix::from_vec(2, 2, vec![1.0, 2.0, 3.0, 4.0]).unwrap();
assert_eq!(m.rows(), 2);
assert_eq!(m.cols(), 2);
Source

pub fn from_vec_with_backend( rows: usize, cols: usize, data: Vec<f32>, backend: Backend, ) -> Self

Creates a matrix from a vector with a specific backend

This is useful for testing specific SIMD code paths.

Source

pub fn from_slice( rows: usize, cols: usize, data: &[f32], ) -> Result<Self, TruenoError>

Creates a matrix from a slice by copying the data

This is a convenience method that copies the slice into an owned vector. For zero-copy scenarios, consider using the data directly with from_vec if you already have an owned Vec.

§Arguments
  • rows - Number of rows
  • cols - Number of columns
  • data - Slice containing matrix elements in row-major order
§Errors

Returns InvalidInput if data.len() != rows * cols

§Example
use trueno::Matrix;

let data = [1.0, 2.0, 3.0, 4.0];
let m = Matrix::from_slice(2, 2, &data).unwrap();
assert_eq!(m.get(0, 0), Some(&1.0));
Source

pub fn zeros(rows: usize, cols: usize) -> Self

Creates a matrix filled with zeros

§Example
use trueno::Matrix;

let m = Matrix::zeros(3, 3);
assert_eq!(m.get(1, 1), Some(&0.0));
Source

pub fn identity(n: usize) -> Self

Creates an identity matrix (square matrix with 1s on diagonal)

§Example
use trueno::Matrix;

let m = Matrix::identity(3);
assert_eq!(m.get(0, 0), Some(&1.0));
assert_eq!(m.get(0, 1), Some(&0.0));
assert_eq!(m.get(1, 1), Some(&1.0));
Source

pub fn rows(&self) -> usize

Returns the number of rows

Source

pub fn cols(&self) -> usize

Returns the number of columns

Source

pub fn shape(&self) -> (usize, usize)

Returns the shape as (rows, cols)

Source

pub fn get(&self, row: usize, col: usize) -> Option<&f32>

Gets a reference to an element at (row, col)

Returns None if indices are out of bounds

Source

pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut f32>

Gets a mutable reference to an element at (row, col)

Returns None if indices are out of bounds

Source

pub fn as_slice(&self) -> &[f32]

Returns a reference to the underlying data

Source

pub fn backend(&self) -> Backend

Returns the backend used by this matrix

Trait Implementations§

Source§

impl<T: Clone> Clone for Matrix<T>

Source§

fn clone(&self) -> Matrix<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Matrix<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Index<(usize, usize)> for Matrix<f32>

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T: PartialEq> PartialEq for Matrix<T>

Source§

fn eq(&self, other: &Matrix<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> StructuralPartialEq for Matrix<T>

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>

§

impl<T> RefUnwindSafe for Matrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for Matrix<T>
where T: Send,

§

impl<T> Sync for Matrix<T>
where T: Sync,

§

impl<T> Unpin for Matrix<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Matrix<T>

§

impl<T> UnwindSafe for Matrix<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,