FieldSet

Enum FieldSet 

Source
pub enum FieldSet {
    Item(FieldConfig),
    Seq(Vec<FieldSet>),
}
Expand description

Field structure definition.

Variants§

§

Item(FieldConfig)

For single Field

§

Seq(Vec<FieldSet>)

For Sequence of Fields

Implementations§

Source§

impl FieldSet

Source

pub fn new_field(range: Range<usize>) -> Self

Create a new field.

use fixed_width::FieldSet;

let field = FieldSet::new_field(0..1);
Source

pub fn name<T: Into<String>>(self, val: T) -> Self

Sets the name of this field. Mainly used when deserializing into a HashMap to derive the keys. (This method is not valid on FieldSet::Seq and cause panic)

use fixed_width::FieldSet;

let fields = FieldSet::Seq(vec![
    FieldSet::new_field(0..1).name("foo"),
    FieldSet::Seq(vec![
        FieldSet::new_field(0..2).name("bar"), FieldSet::new_field(0..3).name("baz")
    ])
]);
Source

pub fn pad_with(self, val: char) -> Self

Sets the character to use as padding the value of this field to its byte width.

§Example
use fixed_width::FieldSet;

let field = FieldSet::new_field(0..1).pad_with('x');
let fields = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::Seq(vec![FieldSet::new_field(0..2), FieldSet::new_field(0..3)]),
])
.pad_with('x');
Source

pub fn justify<T: Into<Justify>>(self, val: T) -> Self

Sets the justification to use fields. Left will align to the left and Right to the right.

§Example
use fixed_width::{FieldSet, Justify};

let field = FieldSet::new_field(0..1).justify(Justify::Right);
let fields = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::Seq(vec![FieldSet::new_field(0..2), FieldSet::new_field(0..3)]),
])
.justify(Justify::Right);
Source

pub fn append(self, item: Self) -> Self

Append FieldSet with the given item.

§Example
use fixed_width::FieldSet;

// Suppose field defined as:
let append_fields_1 = FieldSet::new_field(0..1).append(FieldSet::new_field(1..2));
let append_fields_2 = FieldSet::new_field(0..1).append(
    FieldSet::Seq(vec![
        FieldSet::new_field(1..2),
        FieldSet::new_field(2..3),
    ])
);

// Are identical to:
let fields_1 = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::new_field(1..2),
]);
let fields_2 = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::Seq(vec![
        FieldSet::new_field(1..2),
        FieldSet::new_field(2..3),
    ]),
]);
Source

pub fn extend(self, item: Self) -> Self

Extend FieldSet with the given item.

§Example
use fixed_width::FieldSet;

// Suppose field defined as:
let extend_fields_1 = FieldSet::new_field(0..1).extend(FieldSet::new_field(1..2));
let extend_fields_2 = FieldSet::new_field(0..1).extend(
    FieldSet::Seq(vec![
        FieldSet::new_field(1..2),
        FieldSet::new_field(2..3),
    ])
);

// Are identical to:
let fields_1 = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::new_field(1..2),
]);
let fields_2 = FieldSet::Seq(vec![
    FieldSet::new_field(0..1),
    FieldSet::new_field(1..2),
    FieldSet::new_field(2..3),
]);
Source

pub fn flatten(self) -> Vec<FieldConfig>

Converts FieldSet into flatten Vec<FieldConfig>.

§Example
use fixed_width::{FieldConfig, FieldSet};

let fields = FieldSet::Seq(vec![
    FieldSet::Seq(vec![FieldSet::new_field(0..1), FieldSet::new_field(1..2)]),
    FieldSet::new_field(2..3)
]);
let flatten_fields = vec![
    FieldConfig::new(0..1), FieldConfig::new(1..2), FieldConfig::new(2..3)
];

assert_eq!(format!("{:?}", fields.flatten()), format!("{:?}", flatten_fields));

Trait Implementations§

Source§

impl Clone for FieldSet

Source§

fn clone(&self) -> FieldSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FieldSet

Source§

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

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

impl IntoIterator for FieldSet

Source§

type Item = FieldSet

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<FieldSet>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.