Skip to main content

FieldWriter

Struct FieldWriter 

Source
pub struct FieldWriter { /* private fields */ }
Expand description

Writes fields and gives them back as a RawMessage.

The fields are written in the order of the calls.

use refix_message::{Decimal, FieldWriter, Tag};

let mut body = FieldWriter::new();
body.write_str(Tag(11), "ORDER-1")?;
body.write_str(Tag(55), "ACME")?;
body.write_decimal(Tag(44), Decimal::new(10125, -2));
let body = body.finish();

assert_eq!(body.to_string(), "11=ORDER-1|55=ACME|44=101.25");
assert_eq!(body.get_str(Tag(55))?, Some("ACME"));

Implementations§

Source§

impl FieldWriter

Source

pub fn new() -> Self

A writer with nothing written.

Source

pub fn with_capacity(bytes: usize, fields: usize) -> Self

A writer with room for bytes bytes and fields fields.

Source

pub fn write(&mut self, tag: Tag, value: &[u8]) -> Result<(), WriteError>

Writes a field with value as its bytes.

An empty value and a value that holds the separator are errors. Nothing is written for them.

§Panics

If the fields written pass 4 GiB.

Source

pub fn write_str(&mut self, tag: Tag, value: &str) -> Result<(), WriteError>

Writes a field with value as its text.

Fails and panics as write does.

Source

pub fn write_int(&mut self, tag: Tag, value: i64)

Writes a field with value as an integer.

Panics as write does.

Source

pub fn write_bool(&mut self, tag: Tag, value: bool)

Writes a field with Y for true or N for false.

Panics as write does.

Source

pub fn write_decimal(&mut self, tag: Tag, value: Decimal)

Writes a field with value as a decimal, keeping its scale.

A positive exponent is written as zeros, so Decimal::new(15, 3) is 15000. Panics as write does.

Source

pub fn write_date(&mut self, tag: Tag, value: Date)

Writes a field with value as a date, such as 20261103.

Panics as write does.

Source

pub fn write_time(&mut self, tag: Tag, value: Time)

Writes a field with value as a time of day, such as 09:30:36.250.

The fraction has the digits of the value’s precision. Digits past it are cut, not rounded. Panics as write does.

Source

pub fn write_utc_timestamp(&mut self, tag: Tag, value: UtcTimestamp)

Writes a field with value as a UTC timestamp, such as 20261103-09:30:36.250.

The fraction has the digits of the value’s precision. Digits past it are cut, not rounded. Panics as write does.

Source

pub fn write_month_year(&mut self, tag: Tag, value: MonthYear)

Writes a field with value as a month and year, such as 202612, 20261218 or 202612w3.

Panics as write does.

Source

pub fn write_data( &mut self, length_tag: Tag, tag: Tag, value: &[u8], ) -> Result<(), WriteError>

Writes a data field after the length field that counts its bytes.

The value may hold the separator. An empty value is an error, and nothing is written for it.

Panics as write does.

Source

pub fn write_fields(&mut self, fields: &RawMessage)

Writes every field of fields again, in the same order.

The values are written as they are, without the checks of write. Panics as write does.

Source

pub fn finish(self) -> RawMessage

The fields written, as a message.

Trait Implementations§

Source§

impl Debug for FieldWriter

Source§

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

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

impl Default for FieldWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for FieldWriter

§

impl Freeze for FieldWriter
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<RawField>: Freeze,

§

impl Move for FieldWriter

§

impl RefUnwindSafe for FieldWriter

§

impl Send for FieldWriter
where RawVecInner: Send,

§

impl Sync for FieldWriter
where RawVecInner: Sync,

§

impl Unpin for FieldWriter
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for FieldWriter

§

impl UnwindSafe for FieldWriter
where RawVecInner: 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 = !

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.