Skip to main content

Segment

Enum Segment 

Source
#[non_exhaustive]
pub enum Segment { Block(Vec<Field>), Value { name: String, doc: Option<String>, stated: Option<Stated>, kind: Kind, }, Repeat { name: String, doc: Option<String>, stated: Option<Stated>, element: Kind, count: Count, at: Option<String>, collection: Collection, }, Placed { name: String, doc: Option<String>, stated: Option<Stated>, kind: Kind, at: String, absent: Option<Absence>, }, Switch { name: String, doc: Option<String>, stated: Option<Stated>, on: Discriminant, choice: String, window: Option<Len>, }, Opt { when: Presence, field: Field, }, Checksum { name: String, doc: Option<String>, stated: Option<Stated>, repr: Scalar, algorithm: String, over: Coverage, }, }
Expand description

One part of a message.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Block(Vec<Field>)

Fixed-width fields.

§

Value

A Kind::Var, Kind::Msg or Kind::Text value, whose size is read from the wire.

Fields

§name: String

The field name.

§doc: Option<String>

Documentation.

§stated: Option<Stated>

The #[at] position. Only allowed before any variable-length segment.

§kind: Kind

The type.

§

Repeat

A collection of elements.

Fields

§name: String

The field name.

§doc: Option<String>

Documentation.

§stated: Option<Stated>

The #[at] position. Only allowed before any variable-length segment.

§element: Kind

The element type.

§count: Count

How many elements there are.

§at: Option<String>

The earlier field holding the byte offset of the elements. Encode writes it.

§collection: Collection

The Rust type.

§

Placed

One record at a byte offset read from an earlier field.

The offset counts from the start of the body, which inside a Kind::Msg is that message.

Fields

§name: String

The field name.

§doc: Option<String>

Documentation.

§stated: Option<Stated>

The #[at] position. Only allowed before any variable-length segment.

§kind: Kind

The record: a Kind::Nested or a Kind::Msg.

§at: String

The earlier field holding the offset. Encode writes it.

§absent: Option<Absence>

What makes the record absent, for an Option<T> field.

§

Switch

A field whose arm an earlier value selects.

The arms and their values are in a ChoiceDef. Nothing can follow a switch that has no window and whose choice is open-ended.

Fields

§name: String

The field name.

§doc: Option<String>

Documentation.

§stated: Option<Stated>

The #[at] position. Only allowed before any variable-length segment.

§on: Discriminant

What selects the arm.

§choice: String

The ChoiceDef type.

§window: Option<Len>

A fixed size for the switch, independent of the arm.

None takes the arm’s size. Len::Bytes makes a union, checked by arms_fit. Len::Field reads the size from an earlier field, and encode writes it. With a window, fields can follow the switch.

§

Opt

An optional field.

Encode sets the masked bits and leaves the rest of the flags field alone. Other fields cannot refer to an optional field.

Fields

§when: Presence

When the field is present.

§field: Field

The field.

§

Checksum

A checksum over bytes of the same body.

Encode computes it once the covered bytes are written. Decode verifies it and returns an error on mismatch.

Fields

§name: String

The field name.

§doc: Option<String>

Documentation.

§stated: Option<Stated>

The #[at] position. Only allowed before any variable-length segment.

§repr: Scalar

The integer type.

§algorithm: String

The path of the layline::Checksum algorithm.

§over: Coverage

The bytes it covers.

Implementations§

Source§

impl Segment

Source

pub fn block(fields: Vec<Field>) -> Self

Source

pub fn value(name: &str, kind: Kind) -> Self

A Segment::Value with no documentation or #[at].

Source

pub fn repeat( name: &str, element: Kind, count: Count, at: Option<&str>, collection: Collection, ) -> Self

A Segment::Repeat.

at names the offset field, or is None to read the elements in place.

Source

pub fn placed(name: &str, kind: Kind, at: &str, absent: Option<Absence>) -> Self

A Segment::Placed at the offset in field at. Optional when absent is set.

Source

pub fn switch( name: &str, on: Discriminant, choice: &str, window: Option<Len>, ) -> Self

A Segment::Switch on on, with arms from the choice type choice.

Source

pub fn opt(when: Presence, field: Field) -> Self

Source

pub fn checksum( name: &str, repr: Scalar, algorithm: &str, over: Coverage, ) -> Self

Source

pub fn with_doc(self, text: &str) -> Self

Sets the documentation. Does nothing on a Block.

Source

pub fn with_stated(self, at: Stated) -> Self

Sets the #[at] position. Does nothing on a Block.

Source

pub fn places(&self) -> Vec<&str>

The names of the fields this segment always writes, in wire order.

Optional fields are not included.

Source

pub fn placed_optionally(&self) -> Option<&str>

The name of the field, if it is optional.

Source

pub fn name(&self) -> Option<&str>

The field name, or None for a Block.

Source

pub fn stated(&self) -> Option<Stated>

The #[at] position, if any.

Source

pub fn fixed_bits(&self) -> Option<u64>

The size in bits, or None if it depends on the wire.

Source

pub fn open_ended(&self) -> bool

Whether this segment reads to the end of the body.

Always false for a Switch or Kind::Msg. Generated code checks those against the other type.

Trait Implementations§

Source§

impl Clone for Segment

Source§

fn clone(&self) -> Segment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Segment

Source§

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

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

impl Eq for Segment

Source§

impl PartialEq for Segment

Source§

fn eq(&self, other: &Segment) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Segment

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 = !

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.