Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor<R>
where R: Runtime,
{ /* private fields */ }
Expand description

N-dimensional array stored on a compute device

Tensor is the fundamental data structure in numr. It consists of:

  • Storage: Reference-counted device memory
  • Layout: Shape, strides, and offset defining the view into storage
  • DType: Element type (determined at runtime)

§Zero-Copy Views

Operations like transpose, slice, and reshape create new tensors that share the same underlying storage. This is achieved through:

  • Arc-wrapped storage (reference counting)
  • Modified layout (different strides/offset)

§Example

let a = Tensor::<CpuRuntime>::from_slice(&[1.0f32, 2.0, 3.0, 4.0], &[2, 2], &device);
let b = a.transpose(-1, -2); // Zero-copy, shares storage with a

Implementations§

Source§

impl<R> Tensor<R>
where R: Runtime,

Source

pub fn from_parts(storage: Storage<R>, layout: Layout) -> Tensor<R>

Create a tensor from storage and layout

Source

pub fn empty( shape: &[usize], dtype: <R as Runtime>::DType, device: &<R as Runtime>::Device, ) -> Tensor<R>

Create an uninitialized tensor

§Safety

The contents are uninitialized. Reading before writing is undefined behavior.

§Panics

Panics if allocation fails. Use Self::try_empty in fallible contexts.

Source

pub fn try_empty( shape: &[usize], dtype: <R as Runtime>::DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create an uninitialized tensor (fallible version)

Source

pub fn id(&self) -> TensorId

Get the internal tensor ID for autograd graph tracking.

Source

pub fn storage(&self) -> &Storage<R>

Get the storage

Source

pub fn layout(&self) -> &Layout

Get the layout

Source

pub fn shape(&self) -> &[usize]

Get the shape

Source

pub fn strides(&self) -> &[isize]

Get the strides

Source

pub fn ndim(&self) -> usize

Get the number of dimensions (rank)

Source

pub fn numel(&self) -> usize

Get the total number of elements

Source

pub fn dtype(&self) -> <R as Runtime>::DType

Get the element type

Source

pub fn device(&self) -> &<R as Runtime>::Device

Get the device

Source

pub fn is_contiguous(&self) -> bool

Check if the tensor is contiguous in memory

Source

pub fn is_scalar(&self) -> bool

Check if this is a scalar (0-dimensional tensor)

Source

pub fn size(&self, dim: isize) -> Option<usize>

Get size along a dimension (supports negative indexing)

Source

pub fn dim(&self, index: isize) -> Result<usize, Error>

Get size along a dimension, returning error on invalid index

Source

pub fn rank(&self) -> usize

Number of dimensions (alias for ndim)

Source

pub fn elem_count(&self) -> usize

Total number of elements (alias for numel)

Source

pub fn dims(&self) -> &[usize]

Shape as slice (alias for shape)

Source

pub fn len(&self) -> usize

Total number of elements (alias for numel)

Source

pub fn is_empty(&self) -> bool

Whether the tensor has zero elements

Source

pub fn offset(&self) -> usize

Layout offset into storage (in elements)

Source

pub fn ptr(&self) -> u64

Data pointer adjusted for layout offset. This is the pointer to the first element of this tensor’s view.

Source

pub fn owns_memory(&self) -> bool

Whether the underlying storage is owned (will deallocate on drop)

Source

pub fn shares_storage_with(&self, other: &Tensor<R>) -> bool

Check if two tensors share the same storage

Source

pub fn ref_count(&self) -> usize

Storage reference count

Source

pub fn dims1(&self) -> Result<usize, Error>

Unpack shape of a 1D tensor

Source

pub fn dims2(&self) -> Result<(usize, usize), Error>

Unpack shape of a 2D tensor

Source

pub fn dims3(&self) -> Result<(usize, usize, usize), Error>

Unpack shape of a 3D tensor

Source

pub fn dims4(&self) -> Result<(usize, usize, usize, usize), Error>

Unpack shape of a 4D tensor

Source

pub fn dims5(&self) -> Result<(usize, usize, usize, usize, usize), Error>

Unpack shape of a 5D tensor

Source

pub fn from_storage_contiguous( storage: Storage<R>, shape: &[usize], ) -> Tensor<R>

Create tensor from storage and contiguous layout

Source

pub fn transpose(&self, dim0: isize, dim1: isize) -> Result<Tensor<R>, Error>

Transpose two dimensions (zero-copy)

Source

pub fn t(&self) -> Result<Tensor<R>, Error>

Transpose last two dimensions (matrix transpose)

Source

pub fn reshape(&self, shape: &[usize]) -> Result<Tensor<R>, Error>

Reshape to a new shape (zero-copy if contiguous)

Source

pub fn flatten(&self) -> Result<Tensor<R>, Error>

Flatten to 1D (zero-copy if contiguous)

Source

pub fn squeeze(&self, dim: Option<isize>) -> Tensor<R>

Remove dimensions of size 1

Source

pub fn unsqueeze(&self, dim: isize) -> Result<Tensor<R>, Error>

Add a dimension of size 1

Source

pub fn view(&self, shape: &[usize]) -> Result<Tensor<R>, Error>

View tensor with different shape (alias for reshape)

Source

pub fn permute(&self, dims: &[usize]) -> Result<Tensor<R>, Error>

Permute dimensions (zero-copy)

Reorders the dimensions of the tensor according to the given permutation. This is a view operation - no data is copied.

§Arguments
  • dims - New order of dimensions. Must be a permutation of 0..ndim.
§Example
let tensor = Tensor::<CpuRuntime>::from_slice(&data, &[2, 3, 4], &device);
let permuted = tensor.permute(&[2, 0, 1])?; // Shape becomes [4, 2, 3]
Source

pub fn narrow( &self, dim: isize, start: usize, length: usize, ) -> Result<Tensor<R>, Error>

Narrow a dimension (zero-copy slice)

Returns a view of the tensor narrowed to a contiguous subset of elements along a single dimension. This is a view operation - no data is copied.

§Arguments
  • dim - Dimension to narrow (supports negative indexing)
  • start - Starting index in that dimension
  • length - Number of elements to keep
§Example
let tensor = Tensor::<CpuRuntime>::from_slice(&data, &[4, 5, 6], &device);
let narrowed = tensor.narrow(1, 1, 3)?; // Shape becomes [4, 3, 6]
Source

pub fn broadcast_to(&self, shape: &[usize]) -> Result<Tensor<R>, Error>

Broadcast to a target shape (zero-copy)

Source

pub fn flip(&self, dim: isize) -> Result<Tensor<R>, Error>

Flip (reverse) tensor along a dimension (zero-copy)

Reverses the order of elements along the specified dimension. This is a view operation - no data is copied.

§Arguments
  • dim - Dimension to flip (supports negative indexing)
§Example
let tensor = Tensor::<CpuRuntime>::from_slice(&[1.0, 2.0, 3.0, 4.0], &[2, 2], &device);
let flipped = tensor.flip(0)?; // Reverse rows: [[3, 4], [1, 2]]
let flipped = tensor.flip(-1)?; // Reverse columns: [[2, 1], [4, 3]]
Source

pub fn flip_dims(&self, dims: &[isize]) -> Result<Tensor<R>, Error>

Flip (reverse) tensor along multiple dimensions (zero-copy)

§Arguments
  • dims - Dimensions to flip (supports negative indexing)
§Example
let tensor = Tensor::<CpuRuntime>::from_slice(&data, &[2, 3, 4], &device);
let flipped = tensor.flip_dims(&[0, 2])?; // Flip first and last dimensions
Source

pub fn contiguous(&self) -> Tensor<R>

Make tensor contiguous (copy if needed)

If the tensor is already contiguous, returns a view (zero-copy). Otherwise, allocates new storage and copies the data to a contiguous layout.

§Backend Support

This method uses Runtime::copy_strided which handles strided copies correctly for each backend:

  • CPU/CUDA: Uses pointer arithmetic (handles can be offset directly)
  • WGPU: Uses compute shader (buffer IDs don’t support arithmetic)
Source

pub fn detach(&self) -> Tensor<R>

Detach from computation graph (for autograd)

Source

pub fn to_vec<T>(&self) -> Vec<T>
where T: Pod,

Copy tensor data to a Vec on the host

For contiguous tensors, this copies only the viewed portion of the storage, respecting the tensor’s shape and offset.

Source

pub fn record_event(&self) -> Result<u64, Error>

Record an event on the compute stream for this tensor’s device.

Call this BEFORE launching additional compute work, then pass the event to to_vec_pipelined AFTER launching the compute work. This allows the copy to proceed as soon as the event fires, while compute continues.

Source

pub fn to_vec_pipelined<T>(&self, event: u64) -> Result<Vec<T>, Error>
where T: Pod,

Copy tensor data to a Vec using the pipelined copy stream, synchronized via a previously recorded event.

On CUDA, syncs only the copy stream — compute stream keeps running.

Source

pub fn item<T>(&self) -> Result<T, Error>
where T: Pod + Copy,

Extract the scalar value from a single-element tensor

This is the idiomatic way to get a scalar value from a tensor for use in Rust control flow (convergence checks, comparisons, etc.).

§Returns

The single element as type T, or an error if the tensor doesn’t contain exactly one element.

§Example
let loss_val: f32 = loss.item()?;
if loss_val < 1.0 {
    // training converged
}
Source§

impl<R> Tensor<R>
where R: Runtime,

Source

pub fn try_zeros_generic( shape: &[usize], dtype: <R as Runtime>::DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with zeros (generic, works with any DType)

Source

pub fn try_ones_generic( shape: &[usize], dtype: <R as Runtime>::DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with ones (generic, works with any DType)

Source

pub fn try_full_scalar_generic( shape: &[usize], dtype: <R as Runtime>::DType, value: f64, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with a scalar value (generic, works with any DType)

Uses DataType::fill_bytes to generate the fill pattern, so it works with any DType that implements the trait (including boostr’s quantized types).

Source

pub fn try_from_bytes( bytes: &[u8], shape: &[usize], dtype: <R as Runtime>::DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor from raw bytes with specified dtype (generic)

Source§

impl<R> Tensor<R>
where R: Runtime<DType = DType>,

Source

pub fn from_slice<T>( data: &[T], shape: &[usize], device: &<R as Runtime>::Device, ) -> Tensor<R>
where T: Element,

Create a tensor from a slice of data

§Panics

Panics if data.len() does not equal the product of the shape dimensions. For a fallible alternative, use Self::try_from_slice.

§Example
let tensor = Tensor::<CpuRuntime>::from_slice(&[1.0f32, 2.0, 3.0, 4.0], &[2, 2], &device);
Source

pub fn try_from_slice<T>( data: &[T], shape: &[usize], device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>
where T: Element,

Create a tensor from a slice of data (fallible version)

Returns an error if data.len() does not equal the product of the shape dimensions, or if memory allocation fails.

§Example
let tensor = Tensor::<CpuRuntime>::try_from_slice(&[1.0f32, 2.0, 3.0, 4.0], &[2, 2], &device)?;
Source

pub fn zeros( shape: &[usize], dtype: DType, device: &<R as Runtime>::Device, ) -> Tensor<R>

Create a tensor filled with zeros

This properly initializes memory to zero on all backends (CPU and GPU).

Source

pub fn try_zeros( shape: &[usize], dtype: DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with zeros (fallible version)

Source

pub fn ones( shape: &[usize], dtype: DType, device: &<R as Runtime>::Device, ) -> Tensor<R>

Create a tensor filled with ones

Source

pub fn try_ones( shape: &[usize], dtype: DType, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with ones (fallible version)

Source

pub fn full_scalar( shape: &[usize], dtype: DType, value: f64, device: &<R as Runtime>::Device, ) -> Tensor<R>

Create a tensor filled with a scalar value

The scalar is converted to the target dtype.

Source

pub fn try_full_scalar( shape: &[usize], dtype: DType, value: f64, device: &<R as Runtime>::Device, ) -> Result<Tensor<R>, Error>

Create a tensor filled with a scalar value (fallible version)

Source§

impl<R> Tensor<R>
where R: Runtime,

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, Error>

Serialize tensor data to raw bytes

Makes tensor contiguous first if needed, then copies raw bytes from device.

Source

pub fn clone_deep(&self) -> Result<Tensor<R>, Error>

Clone tensor with new storage (deep copy)

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: BinaryOps<R>,

Source

pub fn add(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise addition: self + other

Source

pub fn sub(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise subtraction: self - other

Source

pub fn mul(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise multiplication: self * other

Source

pub fn div(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise division: self / other

Source

pub fn pow(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise power: self ^ other

Source

pub fn maximum(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise maximum: max(self, other)

Source

pub fn minimum(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise minimum: min(self, other)

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: UnaryOps<R>,

Source

pub fn neg(&self) -> Result<Tensor<R>, Error>

Element-wise negation

Source

pub fn abs(&self) -> Result<Tensor<R>, Error>

Element-wise absolute value

Source

pub fn sqrt(&self) -> Result<Tensor<R>, Error>

Element-wise square root

Source

pub fn exp(&self) -> Result<Tensor<R>, Error>

Element-wise exponential

Source

pub fn log(&self) -> Result<Tensor<R>, Error>

Element-wise natural log

Source

pub fn sin(&self) -> Result<Tensor<R>, Error>

Element-wise sine

Source

pub fn cos(&self) -> Result<Tensor<R>, Error>

Element-wise cosine

Source

pub fn tan(&self) -> Result<Tensor<R>, Error>

Element-wise tangent

Source

pub fn tanh(&self) -> Result<Tensor<R>, Error>

Element-wise hyperbolic tangent

Source

pub fn recip(&self) -> Result<Tensor<R>, Error>

Element-wise reciprocal (1/x)

Source

pub fn floor(&self) -> Result<Tensor<R>, Error>

Element-wise floor

Source

pub fn ceil(&self) -> Result<Tensor<R>, Error>

Element-wise ceil

Source

pub fn round(&self) -> Result<Tensor<R>, Error>

Element-wise round

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: ScalarOps<R>,

Source

pub fn add_scalar(&self, scalar: f64) -> Result<Tensor<R>, Error>

Add scalar: self + scalar

Source

pub fn mul_scalar(&self, scalar: f64) -> Result<Tensor<R>, Error>

Multiply by scalar: self * scalar

Source

pub fn scale(&self, scalar: f64) -> Result<Tensor<R>, Error>

Scale alias for mul_scalar

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: ActivationOps<R>,

Source

pub fn relu(&self) -> Result<Tensor<R>, Error>

ReLU activation: max(0, x)

Source

pub fn sigmoid(&self) -> Result<Tensor<R>, Error>

Sigmoid activation: 1 / (1 + exp(-x))

Source

pub fn gelu(&self) -> Result<Tensor<R>, Error>

GELU activation

Source

pub fn silu(&self) -> Result<Tensor<R>, Error>

SiLU/Swish activation: x * sigmoid(x)

Source

pub fn softmax(&self, dim: isize) -> Result<Tensor<R>, Error>

Softmax along dimension

Source

pub fn log_softmax(&self, dim: isize) -> Result<Tensor<R>, Error>

Log-softmax along dimension: log(softmax(x, dim))

Source

pub fn dropout(&self, p: f64, training: bool) -> Result<Tensor<R>, Error>

Dropout: randomly zero elements with probability p during training

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: ReduceOps<R>,

Source

pub fn sum(&self, dims: &[usize], keepdim: bool) -> Result<Tensor<R>, Error>

Sum along dimensions

Source

pub fn mean(&self, dims: &[usize], keepdim: bool) -> Result<Tensor<R>, Error>

Mean along dimensions

Source

pub fn max(&self, dims: &[usize], keepdim: bool) -> Result<Tensor<R>, Error>

Max along dimensions

Source

pub fn min(&self, dims: &[usize], keepdim: bool) -> Result<Tensor<R>, Error>

Min along dimensions

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: MatmulOps<R>,

Source

pub fn matmul(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Matrix multiplication: self @ other

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: NormalizationOps<R>,

Source

pub fn rms_norm(&self, weight: &Tensor<R>, eps: f32) -> Result<Tensor<R>, Error>

RMS normalization: x / RMS(x) * weight

Source

pub fn layer_norm( &self, weight: &Tensor<R>, bias: &Tensor<R>, eps: f32, ) -> Result<Tensor<R>, Error>

Layer normalization: (x - mean) / sqrt(var + eps) * weight + bias

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: CompareOps<R>,

Source

pub fn eq(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise equality

Source

pub fn gt(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise greater than

Source

pub fn lt(&self, other: &Tensor<R>) -> Result<Tensor<R>, Error>

Element-wise less than

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: IndexingOps<R>,

Source

pub fn index_select( &self, dim: usize, indices: &Tensor<R>, ) -> Result<Tensor<R>, Error>

Select elements along a dimension using indices

Source

pub fn argmax(&self, dim: usize, keepdim: bool) -> Result<Tensor<R>, Error>

Argmax along a dimension

Source

pub fn argmin(&self, dim: usize, keepdim: bool) -> Result<Tensor<R>, Error>

Argmin along a dimension

Source

pub fn masked_fill( &self, mask: &Tensor<R>, value: f64, ) -> Result<Tensor<R>, Error>

Fill tensor with value where mask is true

Source

pub fn slice_assign( &self, src: &Tensor<R>, dim: usize, start: usize, ) -> Result<Tensor<R>, Error>

Assign src into a slice of self along dim starting at start.

Returns a new tensor with the slice region replaced by src.

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: ShapeOps<R>,

Source

pub fn cat(tensors: &[&Tensor<R>], dim: isize) -> Result<Tensor<R>, Error>

Concatenate tensors along a dimension

Source

pub fn stack(tensors: &[&Tensor<R>], dim: isize) -> Result<Tensor<R>, Error>

Stack tensors along a new dimension

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: CumulativeOps<R>,

Source

pub fn cumsum(&self, dim: isize) -> Result<Tensor<R>, Error>

Cumulative sum along a dimension

Source

pub fn cumprod(&self, dim: isize) -> Result<Tensor<R>, Error>

Cumulative product along a dimension

Source

pub fn logsumexp( &self, dims: &[usize], keepdim: bool, ) -> Result<Tensor<R>, Error>

Log-sum-exp along specified dimensions (numerically stable)

Computes log(sum(exp(x))) in a numerically stable way: logsumexp(x) = max(x) + log(sum(exp(x - max(x))))

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: TypeConversionOps<R>,

Source

pub fn to_dtype(&self, dtype: DType) -> Result<Tensor<R>, Error>

Convert tensor to a different dtype

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: UtilityOps<R>,

Source

pub fn clamp(&self, min: f64, max: f64) -> Result<Tensor<R>, Error>

Clamp values to [min, max]

Source

pub fn one_hot(&self, num_classes: usize) -> Result<Tensor<R>, Error>

One-hot encode indices

Source§

impl<R> Tensor<R>
where R: Runtime, <R as Runtime>::Client: ConvOps<R>,

Source

pub fn conv1d( &self, weight: &Tensor<R>, bias: Option<&Tensor<R>>, stride: usize, padding: PaddingMode, dilation: usize, groups: usize, ) -> Result<Tensor<R>, Error>

1D convolution

Trait Implementations§

Source§

impl<R> Clone for Tensor<R>
where R: Runtime,

Source§

fn clone(&self) -> Tensor<R>

Clone creates a new tensor sharing the same storage (zero-copy)

1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for Tensor<R>
where R: Runtime,

Source§

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

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

impl<R> Display for Tensor<R>
where R: Runtime,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R> Freeze for Tensor<R>

§

impl<R> RefUnwindSafe for Tensor<R>

§

impl<R> Send for Tensor<R>

§

impl<R> Sync for Tensor<R>

§

impl<R> Unpin for Tensor<R>

§

impl<R> UnsafeUnpin for Tensor<R>

§

impl<R> UnwindSafe for Tensor<R>

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
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> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.