ChunkWriter

Struct ChunkWriter 

Source
pub struct ChunkWriter<W> { /* private fields */ }
Expand description

This struct is used to write out chunks to a file.

Implementations§

Source§

impl<W: Write + Seek> ChunkWriter<W>

Source

pub fn id(&self) -> ChunkId

Returns the chunk ID

Source

pub fn offset(&self) -> u64

Returns the offset at which this chunk is written in the underlying writer. Similar to Chunk::offset, this is is usually 0 for child chunks, since the use a ContentWriter, which only sees the children data.

Source

pub fn content_len(&self) -> u32

Returns the current length of the contents.

Source

pub fn children_len(&self) -> u32

Returns the current length of the children data. This is the total number of bytes written for children chunks.

Source

pub fn content_writer<'w, F: FnMut(&mut ContentWriter<&'w mut W>) -> Result<(), WriteError>>( &'w mut self, f: F, ) -> Result<(), WriteError>

Writes data to the chunks content.

Note, that this must be called before any calls to child_writer.

§Example
use std::io::Write;

chunk_writer.content_writer(|writer| {
    // `writer` implements `std::io::Write + std::io::Seek`.
    writer.write_all(b"Hello World")?;
    Ok(())
})
§Panics

Panics, if children have been written already.

Source

pub fn write_content(&mut self, data: &[u8]) -> Result<(), WriteError>

Writes the given slice to the chunk’s data.

Source

pub fn child_writer<'w, F: FnMut(&mut ChildWriter<'w, W>) -> Result<(), WriteError>>( &'w mut self, chunk_id: ChunkId, f: F, ) -> Result<(), WriteError>

Writes children chunks to this chunk. Note, that after a child has been written to a chunk, you can’t write any more data to its contents.

§Example
chunk_writer.child_writer(ChunkId::Main, |child_writer| {
    // `child_writer` is just another `ChunkWriter`.
    child_writer.write_content(b"Hello World")?;
    Ok(())
})
Source

pub fn child_content_writer<'w, F: FnMut(&mut ContentWriter<&mut ContentWriter<&'w mut W>>) -> Result<(), WriteError>>( &'w mut self, chunk_id: ChunkId, f: F, ) -> Result<(), WriteError>

Short-hand to opening and child-writer and then a content-writer to that child. Useful, if you want to write a child with only content data.

Trait Implementations§

Source§

impl<W: Debug> Debug for ChunkWriter<W>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: FloatComponent, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more