Skip to main content

ComponentBytes

Trait ComponentBytes 

Source
pub trait ComponentBytes<T: Pod>
where Self: ComponentSlice<T>,
{ // Provided methods fn as_bytes(&self) -> &[u8] ⓘ { ... } fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ { ... } }
Expand description

Use ::bytemuck::cast_slice() instead.

Casting a slice of RGB/A values to a slice of u8

If instead of RGB8 you use RGB<MyCustomType>, and you want to cast from/to that custom type, implement the Plain trait for it:

unsafe impl rgb::Pod for MyCustomType {}
unsafe impl rgb::Zeroable for MyCustomType {}

Plain types are not allowed to contain struct padding, booleans, chars, enums, references or pointers.

Provided Methods§

Source

fn as_bytes(&self) -> &[u8] ⓘ

The components interpreted as raw bytes, in machine’s native endian. In RGB bytes of the red component are first.

Source

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

The components interpreted as raw bytes, in machine’s native endian. In RGB bytes of the red component are first.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Pod> ComponentBytes<T> for [Abgr<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Argb<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Bgr<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Bgra<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Gray<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [GrayAlpha<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Grb<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Rgb<T>]

Available on crate feature as-bytes only.
Source§

impl<T: Pod> ComponentBytes<T> for [Rgba<T>]

Available on crate feature as-bytes only.

Implementors§