[][src]Struct canvas::Rec

pub struct Rec<P: AsBytes + FromBytes> { /* fields omitted */ }

A reinterpretable vector for an array of pixels.

It allows efficient conversion to other pixel representations, that is effective reinterpretation casts.

Methods

impl<P: AsBytes + FromBytes> Rec<P>[src]

pub fn new(count: usize) -> Self where
    P: AsPixel
[src]

Allocate a pixel buffer by the pixel count.

Panics

This function will panic when the byte-length of the slice with the provided count would exceed the possible usize values. To avoid this, use bytes_for_pixel with manual calculation of the byte length instead.

This function will also panic if the allocation fails.

pub fn new_for_pixel(pixel: Pixel<P>, count: usize) -> Self[src]

Allocate a pixel buffer by the pixel count.

Provides the opportunity to construct the pixel argument via other means than the trait, for example a dynamically checked expression.

Panics

This function will panic when the byte-length of the slice with the provided count would exceed the possible usize values. To avoid this, use bytes_for_pixel with manual calculation of the byte length instead.

This function will also panic if the allocation fails.

pub fn bytes_for_pixel(pixel: Pixel<P>, mem_size: usize) -> Self[src]

Allocate a pixel buffer by providing the byte count you wish to allocate.

Panics

This function will panic if the allocation fails.

pub fn resize(&mut self, count: usize)[src]

Change the number of pixels.

This will always reallocate the buffer if the size exceeds the current capacity.

Panics

This function will panic when the byte-length of the slice with the provided count would exceed the possible usize values. To avoid this, use resize_bytes with manual calculation of the byte length instead.

This function will also panic if an allocation is necessary but fails.

pub fn resize_bytes(&mut self, bytes: usize)[src]

Change the size in bytes.

The length is afterwards equal to bytes / mem::size_of::<P>(), i.e. the quotient rounded down.

This will always reallocate the buffer if the size exceeds the current capacity.

Panics

This function will panic if an allocation is necessary but fails.

pub fn reuse(&mut self, count: usize) -> Result<(), ReuseError>[src]

Change the number of pixels without reallocation.

Returns Ok when the resizing was successfully completed to the requested size and returns Err if this could not have been performed without a reallocation. This function will also never deallocate memory.

// Initial allocation may panic due to allocation error for now.
let mut buffer: Rec<u16> = Rec::new(100);
buffer.reuse(0)
    .expect("Requested size smaller than allocation");
buffer.reuse(100)
    .expect("The buffer didn't shrink from previous reuse");

// Capacity may be larger than requested size at initialization.
let capacity = buffer.capacity();
buffer.reuse(capacity)
    .expect("Set to full underlying allocation size.");

pub fn reuse_bytes(&mut self, bytes: usize) -> Result<(), ReuseError>[src]

Change the number of bytes without reallocation.

Returns Ok when the resizing was successfully completed to the requested size and returns Err with the new byte size otherwise.

pub fn shrink_to_fit(&mut self)[src]

Reallocate the slice to contain exactly as many bytes as necessary.

The number of contained elements is not changed. However, the number of elements interpreted as a different type may change.

let rec_u8 = Rec::<u8>::new(7);
assert_eq!(rec_u8.len(), 7);

let mut rec_u32 = rec_u8.reinterpret::<u32>();
assert_eq!(rec_u32.len(), 1);
rec_u32.shrink_to_fit();

let rec_u8 = rec_u32.reinterpret::<u8>();
assert_eq!(rec_u8.len(), 4);

Panics

This function will panic if the allocation fails.

pub fn as_slice(&self) -> &[P][src]

pub fn as_mut_slice(&mut self) -> &mut [P][src]

pub fn len(&self) -> usize[src]

The number of accessible elements for the current type.

pub fn capacity(&self) -> usize[src]

The number of elements that can fit without reallocation.

pub fn as_bytes(&self) -> &[u8][src]

pub fn as_bytes_mut(&mut self) -> &mut [u8][src]

pub fn byte_len(&self) -> usize[src]

The total number of managed bytes.

This will not change even through a reinterpretation casts. This corresponds to the capacity of the storage.

pub fn byte_capacity(&self) -> usize[src]

The total number of managable bytes.

pub fn reinterpret<Q>(self) -> Rec<Q> where
    Q: AsPixel + AsBytes + FromBytes
[src]

Reinterpret the buffer for a different type of pixel.

See reinterpret_to for details.

pub fn reinterpret_to<Q>(self, pixel: Pixel<Q>) -> Rec<Q> where
    Q: AsBytes + FromBytes
[src]

Reinterpret the buffer for a different type of pixel.

Note that this may leave some of the underlying pixels unaccessible if the new type is larger than the old one and the allocation was not a multiple of the new size. Conversely, some new bytes may become accessible if the memory length was not a multiple of the previous pixel type's length.

Trait Implementations

impl<P: AsBytes + FromBytes + Eq> Eq for Rec<P>[src]

impl<P: AsBytes + FromBytes + Ord> Ord for Rec<P>[src]

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<P: AsBytes + FromBytes + PartialEq> PartialEq<Rec<P>> for Rec<P>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl<P: AsBytes + FromBytes> Clone for Rec<P>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<P: AsBytes + FromBytes + PartialOrd> PartialOrd<Rec<P>> for Rec<P>[src]

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<P: AsBytes + FromBytes + AsPixel> Default for Rec<P>[src]

impl<P: AsBytes + FromBytes> DerefMut for Rec<P>[src]

impl<P: AsBytes + FromBytes> Deref for Rec<P>[src]

type Target = [P]

The resulting type after dereferencing.

impl<P: AsBytes + FromBytes + Debug> Debug for Rec<P>[src]

Auto Trait Implementations

impl<P> Send for Rec<P> where
    P: Send

impl<P> Sync for Rec<P> where
    P: Sync

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]