Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer<'a> { /* private fields */ }
Available on crate features micro-qr or qr or rmqr only.
Expand description

Renders an encoded symbol at exact output dimensions.

Implementations§

Source§

impl<'a> Renderer<'a>

Source

pub const fn new(symbol: &'a Symbol, size: usize) -> Self

Creates a renderer with an exact square output size and the standard quiet zone for the symbol family.

Source

pub const fn new_with_dimensions( symbol: &'a Symbol, width: usize, height: usize, ) -> Self

Creates a renderer with exact output dimensions and the standard quiet zone for the symbol family.

Source

pub const fn quiet_zone(self, modules: usize) -> Self

Sets the minimum quiet zone in modules before any extra centering pixels.

Source

pub fn to_luma8(self) -> Result<Vec<u8>, RenderError>

Renders an 8-bit grayscale image in row-major order.

Source

pub fn write_svg<W: IoWrite>( self, writer: W, description: Option<impl AsRef<str>>, ) -> Result<(), RenderError>

Available on crate feature std only.

Writes an SVG document to a writer.

The description must contain only characters allowed by XML 1.0; markup characters are escaped, but callers must remove or replace disallowed XML characters before rendering. Pass None::<&str> when no description is needed.

Source

pub fn to_svg_string( self, description: Option<impl AsRef<str>>, ) -> Result<String, RenderError>

Renders an SVG document as a UTF-8 string.

The description must contain only characters allowed by XML 1.0; markup characters are escaped, but callers must remove or replace disallowed XML characters before rendering. Pass None::<&str> when no description is needed.

Source

pub async fn write_svg_async<W: TokioAsyncWrite + Unpin>( self, writer: W, description: Option<impl AsRef<str>>, ) -> Result<(), RenderError>

Available on crate feature tokio only.

Renders an SVG document in memory, then writes and flushes it to a tokio asynchronous writer.

The description must contain only characters allowed by XML 1.0; markup characters are escaped, but callers must remove or replace disallowed XML characters before rendering. Pass None::<&str> when no description is needed.

Source

pub fn save_svg( self, path: impl AsRef<Path>, description: Option<impl AsRef<str>>, ) -> Result<(), RenderError>

Available on crate feature std only.

Atomically saves an SVG document after rendering succeeds.

The description must contain only characters allowed by XML 1.0; markup characters are escaped, but callers must remove or replace disallowed XML characters before rendering. Pass None::<&str> when no description is needed.

Source

pub async fn save_svg_async( self, path: impl AsRef<Path>, description: Option<impl AsRef<str>>, ) -> Result<(), RenderError>

Available on crate feature tokio only.

Atomically saves an SVG document after rendering succeeds, offloading the write to tokio’s blocking pool.

Like save_svg, the write goes through a temporary file, so an existing file is left untouched if it fails. The description must contain only characters allowed by XML 1.0; markup characters are escaped, but callers must remove or replace disallowed XML characters before rendering. Pass None::<&str> when no description is needed.

Source

pub fn write_png<W: IoWrite>(self, writer: W) -> Result<(), RenderError>

Available on crate feature image only.

Writes a grayscale PNG image to a writer.

Source

pub fn to_png_vec(self) -> Result<Vec<u8>, RenderError>

Available on crate feature image only.

Renders a grayscale PNG image into a byte vector.

Source

pub async fn write_png_async<W: TokioAsyncWrite + Unpin>( self, writer: W, ) -> Result<(), RenderError>

Available on crate features image and tokio only.

Renders a PNG image in memory, then writes and flushes it to a tokio asynchronous writer.

Source

pub fn save_png(self, path: impl AsRef<Path>) -> Result<(), RenderError>

Available on crate feature image only.

Atomically saves a PNG image after rendering succeeds.

Source

pub async fn save_png_async( self, path: impl AsRef<Path>, ) -> Result<(), RenderError>

Available on crate features image and tokio only.

Atomically saves a PNG image after rendering succeeds, offloading the write to tokio’s blocking pool.

Like save_png, the write goes through a temporary file, so an existing file is left untouched if it fails.

Source

pub fn to_image_buffer( self, ) -> Result<ImageBuffer<Luma<u8>, Vec<u8>>, RenderError>

Available on crate feature image only.

Renders a grayscale image buffer.

Trait Implementations§

Source§

impl<'a> Clone for Renderer<'a>

Source§

fn clone(&self) -> Renderer<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Renderer<'a>

Source§

impl<'a> Debug for Renderer<'a>

Source§

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

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

impl Display for Renderer<'_>

Draws the symbol as compact Unicode text using half-block characters, with one module per column and two module rows per line.

The alternate form ({:#}) inverts dark and light modules for dark terminal backgrounds. Pixel dimensions are ignored; only the quiet zone setting applies. Each line ends with a newline.

Note: half-block characters have ambiguous East Asian width and may render as two columns in some CJK terminals, causing misalignment.

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Renderer<'a>

§

impl<'a> RefUnwindSafe for Renderer<'a>

§

impl<'a> Send for Renderer<'a>

§

impl<'a> Sync for Renderer<'a>

§

impl<'a> Unpin for Renderer<'a>

§

impl<'a> UnsafeUnpin for Renderer<'a>

§

impl<'a> UnwindSafe for Renderer<'a>

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V