Skip to main content

Formatter

Struct Formatter 

Source
pub struct Formatter<'b> { /* private fields */ }
Expand description

A TTLV formatter.

§Panics

TTLV uses 32-bit fields to express the size of serialized data, in units of bytes. To guarantee panic-free operation, only the first 4GiB of a given input buffer will be used. A write that would overflow a length field is guaranteed to return TruncationError instead.

Implementations§

Source§

impl<'b> Formatter<'b>

Source

pub const fn new(buffer: &'b mut [MaybeUninit<u8>]) -> Self

Construct a new Formatter.

The input will be truncated to the first 4GiB, and to a multiple of 8 bytes, as per limitations of the TTLV format. It should ideally be aligned to an 8-byte address boundary (for better performance).

Source

pub const unsafe fn from_raw_parts( buffer: &'b mut [MaybeUninit<[u8; 8]>], position: usize, ) -> Self

Construct a new Formatter from its raw parts.

§Safety

Formatter::from_raw_parts(buffer, position) is sound if and only if:

  • position <= buffer.len().
  • buffer[..position] is initialized.
  • buffer.len() * 8 <= 2^32.
Source

pub fn clear(&mut self)

Source

pub fn filled(&self) -> &[[u8; 8]]

The filled part of the buffer.

Source

pub fn filled_mut(&mut self) -> &mut [[u8; 8]]

The filled part of the buffer, mutably.

Source

pub fn remaining(&mut self) -> &mut [MaybeUninit<[u8; 8]>]

The remaining part of the buffer.

Source

pub const fn into_raw_parts(self) -> (&'b mut [MaybeUninit<[u8; 8]>], usize)

Destructure a Formatter into its raw parts.

§Invariants

For (buffer, position) = self.into_raw_parts():

  • Invariant coherent-position: position <= buffer.len().
  • Invariant initialized: buffer[..position] is initialized.
  • Invariant size: buffer.as_flattened().len() <= 2^32.
Source§

impl<'b> Formatter<'b>

Source

pub fn format_struct( &mut self, tag: Tag, ) -> Result<FieldFormatter<'_>, TruncationError>

Format a structure.

The returned sub-formatter should be used to format the fields of the struct; once it is finished, self can continue.

Source

pub fn format_int(&mut self, tag: Tag, value: i32) -> FormatResult

Format an integer.

Source

pub fn format_long_int(&mut self, tag: Tag, value: i64) -> FormatResult

Format a long integer.

Source

pub fn format_big_int(&mut self, tag: Tag, value: &[u8]) -> FormatResult

Format a big integer.

value should be the bytewise digits of a signed (two’s complement) big-endian integer. It will be padded (with leading sign-extension bytes) into a multiple of 8 bytes before being stored.

§Panics

Panics if the length of value (when rounded up to a multiple of 8 bytes) does not fit in a u32.

Source

pub fn format_enum(&mut self, tag: Tag, value: u32) -> FormatResult

Format an enumeration.

Source

pub fn format_bool(&mut self, tag: Tag, value: bool) -> FormatResult

Format a boolean.

Source

pub fn format_text(&mut self, tag: Tag, value: &str) -> FormatResult

Format a text string.

Source

pub fn format_bytes(&mut self, tag: Tag, value: &[u8]) -> FormatResult

Format a byte string.

Source

pub fn format_date_time(&mut self, tag: Tag, value: i64) -> FormatResult

Format a date-time.

Source

pub fn format_interval(&mut self, tag: Tag, value: u32) -> FormatResult

Format an interval.

Auto Trait Implementations§

§

impl<'b> !UnwindSafe for Formatter<'b>

§

impl<'b> Forget for Formatter<'b>

§

impl<'b> Freeze for Formatter<'b>

§

impl<'b> Move for Formatter<'b>

§

impl<'b> RefUnwindSafe for Formatter<'b>

§

impl<'b> Send for Formatter<'b>

§

impl<'b> Sync for Formatter<'b>

§

impl<'b> Unpin for Formatter<'b>

§

impl<'b> UnsafeUnpin for Formatter<'b>

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> Instrument for T

Source§

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

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

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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