Struct SliceWriter

Source
pub(crate) struct SliceWriter<T> {
    data: T,
    offset: usize,
}
Expand description

An object that supports writing into a byte-slice of fixed size.

Since the writer API does not allow all write_* functions to report errors, this type defers any truncated-data errors until you try to retrieve the inner data.

Fields§

§data: T

The object we’re writing into. Must have fewer than usize::LEN bytes.

§offset: usize

Our current write position within that object.

Implementations§

Source§

impl<T> SliceWriter<T>
where T: AsMut<[u8]>,

Source

pub(crate) fn advance(&mut self, n: usize)

Move this writer ahead by n bytes, leaving the original data unchanged.

Source§

impl<T> SliceWriter<T>

Source

pub(crate) fn new(data: T) -> Self

Construct a new SliceWriter

Typically, you would want to use this on a type that implements AsMut<[u8]>, or else it won’t be very useful.

Preexisting bytes in the data object will be unchanged, unless you use the [Writer] API to write to them.

Source

pub(crate) fn try_unwrap(self) -> Result<(T, usize), SliceWriterError>

Try to extract the data from this SliceWriter.

On success (if we did not write “off the end” of the underlying object), return the object and the number of bytes we wrote into it. (Bytes after that position are unchanged.)

On failure (if we tried to write too much), return an error.

Source

pub(crate) fn offset(&self) -> Result<usize, SliceWriterError>

Return the number of bytes written into this SliceWriter so far, or an error if it has overflowed.

Source

pub(crate) fn assert_offset_is(&self, n: usize)

debug_assert that this writer is at position n.

§Panics

Panics if debugging assertions are enabled and the write has overflowed, or is at a position other than n.

Trait Implementations§

Source§

impl<T> Writer for SliceWriter<T>
where T: AsMut<[u8]>,

Source§

fn write_all(&mut self, b: &[u8])

Append a slice to the end of this writer.
§

fn write_u8(&mut self, x: u8)

Append a single u8 to this writer.
§

fn write_u16(&mut self, x: u16)

Append a single u16 to this writer, encoded in big-endian order.
§

fn write_u32(&mut self, x: u32)

Append a single u32 to this writer, encoded in big-endian order.
§

fn write_u64(&mut self, x: u64)

Append a single u64 to this writer, encoded in big-endian order.
§

fn write_u128(&mut self, x: u128)

Append a single u128 to this writer, encoded in big-endian order.
§

fn write_zeros(&mut self, n: usize)

Write n bytes to this writer, all with the value zero. Read more
§

fn write<E>(&mut self, e: &E) -> Result<(), EncodeError>
where E: Writeable + ?Sized,

Encode a Writeable object onto this writer, using its write_onto method.
§

fn write_and_consume<E>(&mut self, e: E) -> Result<(), EncodeError>
where E: WriteableOnce,

Encode a WriteableOnce object onto this writer, using its write_into method.
§

fn write_nested_u8len(&mut self) -> NestedWriter<'_, Self, u8>

Arranges to write a u8 length, and some data whose encoding is that length Read more
§

fn write_nested_u16len(&mut self) -> NestedWriter<'_, Self, u16>

Arranges to writes a u16 length and some data whose encoding is that length
§

fn write_nested_u32len(&mut self) -> NestedWriter<'_, Self, u32>

Arranges to writes a u32 length and some data whose encoding is that length

Auto Trait Implementations§

§

impl<T> Freeze for SliceWriter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for SliceWriter<T>
where T: RefUnwindSafe,

§

impl<T> Send for SliceWriter<T>
where T: Send,

§

impl<T> Sync for SliceWriter<T>
where T: Sync,

§

impl<T> Unpin for SliceWriter<T>
where T: Unpin,

§

impl<T> UnwindSafe for SliceWriter<T>
where T: 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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,