pub trait Canvas: Sized {
type Pixel: Sized;
type Image: Sized;
// Required methods
fn new(
width: u32,
height: u32,
dark_pixel: Self::Pixel,
light_pixel: Self::Pixel,
) -> Self;
fn draw_dark_pixel(&mut self, x: u32, y: u32);
fn into_image(self) -> Self::Image;
// Provided methods
fn validate_dimensions(
_width: u32,
_height: u32,
_dark_pixel: &Self::Pixel,
_light_pixel: &Self::Pixel,
) -> Result<(), RenderError> { ... }
fn draw_dark_rect(&mut self, left: u32, top: u32, width: u32, height: u32) { ... }
}Expand description
Rendering canvas of a QR code image.
Required Associated Types§
Required Methods§
Sourcefn new(
width: u32,
height: u32,
dark_pixel: Self::Pixel,
light_pixel: Self::Pixel,
) -> Self
fn new( width: u32, height: u32, dark_pixel: Self::Pixel, light_pixel: Self::Pixel, ) -> Self
Constructs a new canvas of the given dimensions.
Sourcefn draw_dark_pixel(&mut self, x: u32, y: u32)
fn draw_dark_pixel(&mut self, x: u32, y: u32)
Draws a single dark pixel at the (x, y) coordinate.
Sourcefn into_image(self) -> Self::Image
fn into_image(self) -> Self::Image
Finalize the canvas to a real image.
Provided Methods§
Sourcefn validate_dimensions(
_width: u32,
_height: u32,
_dark_pixel: &Self::Pixel,
_light_pixel: &Self::Pixel,
) -> Result<(), RenderError>
fn validate_dimensions( _width: u32, _height: u32, _dark_pixel: &Self::Pixel, _light_pixel: &Self::Pixel, ) -> Result<(), RenderError>
Checks dimensions and pixel-dependent resource limits before allocation.
The default accepts all dimensions, preserving existing custom and
vector canvases. Buffered backends override this to reject requests that
exceed their allocation budget. Renderer::try_build calls this
before Canvas::new.
§Errors
Returns RenderError::OutputTooLarge when the backend cannot safely
represent or allocate the requested output within its resource limits.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".