[][src]Struct img_parts::ImageEncoder

#[must_use = "iterators are lazy and do nothing unless consumed"]pub struct ImageEncoder<I> { /* fields omitted */ }

An encoder for and image container or for an image chunk

As image containers contain multiple chunks, each one stored as a separate piece of memory, the representation of the entire file is fragmented in memory. This crate tries to be as efficient as possible with memory, by giving access to the underlying fragmented chunks representing the full file, which can then be written or streamed one at at time.

Those chunks can be accessed through an Iterator, similar to how futures::stream::Stream of Bytes are used in the futures crate. A write_to method is also provided, which calls Write::write_all for every chunk returned by the Iterator. The bytes method is provided for cases where the image has to fit into a linear piece of memory. In that case all of the chunks get copied into a single linear piece of memory.

Saving a file to disk

// some RiffChunk just for this example
// this would also work with anything else from this crate that implements `encoder`
let riff_chunk = RiffChunk::new([b'R', b'I', b'F', b'F'], RiffContent::Data(Bytes::new()));

let file = File::create("somefile.webp")?;
riff_chunk.encoder().write_to(file);

This struct is created by the encoder method on

See their documentation for more.

Implementations

impl<I: EncodeAt> ImageEncoder<I>[src]

pub fn read(self) -> ImageEncoderReader<I>

Notable traits for ImageEncoderReader<I>

impl<I: EncodeAt> Read for ImageEncoderReader<I>
[src]

This is supported on crate feature std only.

Turns this ImageEncoder into a reader that will never fail

pub fn write_to<W: Write>(self, writer: W) -> Result<u64>[src]

This is supported on crate feature std only.

Writes this ImageEncoder into a writer

Returns the number of bytes written.

Errors

This methods fails if writing fails.

pub fn bytes(self) -> Bytes[src]

Returns the entire ImageEncoder in a single linear piece of memory

Takes the pieces composing this ImageEncoder and copies them into a linear piece of memory.

If possible write_to should be used instead, since it avoids creating a second in memory copy of the file.

Trait Implementations

impl<I: Clone> Clone for ImageEncoder<I>[src]

impl<I: Debug> Debug for ImageEncoder<I>[src]

impl<I: EncodeAt> From<I> for ImageEncoder<I>[src]

impl<I> From<ImageEncoder<I>> for ImageEncoderReader<I>[src]

impl<I: EncodeAt> Iterator for ImageEncoder<I>[src]

type Item = Bytes

The type of the elements being iterated over.

Auto Trait Implementations

impl<I> RefUnwindSafe for ImageEncoder<I> where
    I: RefUnwindSafe

impl<I> Send for ImageEncoder<I> where
    I: Send

impl<I> Sync for ImageEncoder<I> where
    I: Sync

impl<I> Unpin for ImageEncoder<I> where
    I: Unpin

impl<I> UnwindSafe for ImageEncoder<I> where
    I: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.