Skip to main content

Source

Trait Source 

Source
pub unsafe trait Source {
    // Required methods
    fn dims(&self) -> Dims;
    fn format(&self) -> Format;
    fn pitch(&self) -> usize;
    unsafe fn row_ptr(&self, y: u32) -> *const u8;

    // Provided method
    unsafe fn read_raw(&self, x: u32, y: u32) -> u32 { ... }
}
Expand description

A surface that a Canvas can copy from.

§Safety

Implementors must guarantee that, for every y < dims().h, Self::row_ptr returns a pointer to at least dims().w * format().bytes_per_pixel() readable bytes, and that the pointer stays valid for as long as self is borrowed.

Required Methods§

Source

fn dims(&self) -> Dims

Source

fn format(&self) -> Format

Source

fn pitch(&self) -> usize

Bytes per row.

Safe to call on its own: it is only used to detect a contiguous buffer for the multi-row fast path, never to index memory.

Source

unsafe fn row_ptr(&self, y: u32) -> *const u8

Pointer to the first pixel of row y.

§Safety

y must be in 0..dims().h.

Provided Methods§

Source

unsafe fn read_raw(&self, x: u32, y: u32) -> u32

Read one pixel with no volatile semantics.

Defaulted so both Canvas and View share the exact same decoding rules.

§Safety

x and y must be inside the surface.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Source for View<'_>

Source§

impl<O: PixelOps> Source for Canvas<'_, O>

Source§

impl<O: PixelOps> Source for OwnedSurface<O>