Encoder

Struct Encoder 

Source
pub struct Encoder<W: Write> { /* private fields */ }
Expand description

Encoder for XBM images.

Implementations§

Source§

impl<W: Write> Encoder<W>

Source

pub const fn new(writer: W) -> Self

Creates a new Encoder.

§Examples
let buf = [].as_mut_slice();
let encoder = Encoder::new(buf);
Source

pub fn encode( self, buf: impl AsRef<[u8]>, name: impl AsRef<str>, width: u32, height: u32, x_hot: Option<u32>, y_hot: Option<u32>, ) -> Result<(), Error>

Encodes the binary image buf.

0 represents a white pixel and 1 represents a black pixel.

name accepts a string which follow the specification in Unicode Standard Annex #31, but it is recommended that name be restricted to the ASCII subset of XID_Start and XID_Continue.

width should be a multiple of 8.

§Errors

Returns Err if an error occurs during I/O operations.

§Panics

Panics if the length of buf and the image dimensions (the width multiplied by the height) are different.

§Examples
// "B" (8x7)
let pixels = b"\x00\x00\x00\x00\x00\x00\x00\x00\
               \x00\x00\x01\x01\x01\x00\x00\x00\
               \x00\x00\x01\x00\x00\x01\x00\x00\
               \x00\x00\x01\x01\x01\x00\x00\x00\
               \x00\x00\x01\x00\x00\x01\x00\x00\
               \x00\x00\x01\x01\x01\x00\x00\x00\
               \x00\x00\x00\x00\x00\x00\x00\x00";

let mut buf = [u8::default(); 131];
let encoder = Encoder::new(buf.as_mut_slice());
encoder.encode(pixels, "image", 8, 7, None, None).unwrap();
assert_eq!(buf, *include_bytes!("../tests/data/basic.xbm"));

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for Encoder<W>

Source§

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

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

impl<W: Write> ImageEncoder for Encoder<W>

Available on crate feature image only.
Source§

fn write_image( self, buf: &[u8], width: u32, height: u32, color_type: ExtendedColorType, ) -> ImageResult<()>

Writes all the bytes in an image to the encoder. Read more
Source§

fn set_icc_profile( &mut self, icc_profile: Vec<u8>, ) -> Result<(), UnsupportedError>

Set the ICC profile to use for the image. Read more
Source§

fn set_exif_metadata(&mut self, exif: Vec<u8>) -> Result<(), UnsupportedError>

Set the EXIF metadata to use for the image. Read more

Auto Trait Implementations§

§

impl<W> Freeze for Encoder<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for Encoder<W>
where W: RefUnwindSafe,

§

impl<W> Send for Encoder<W>
where W: Send,

§

impl<W> Sync for Encoder<W>
where W: Sync,

§

impl<W> Unpin for Encoder<W>
where W: Unpin,

§

impl<W> UnwindSafe for Encoder<W>
where W: UnwindSafe,

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<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, 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.