Skip to main content

OptBlock

Struct OptBlock 

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

Represent an optional block as defined by TR-31.

Each block contains:

  • a two-character identifier,
  • ASCII data,
  • the encoded total block length,
  • an optional link to another block.

Implementations§

Source§

impl OptBlock

Source

pub fn new( id: &str, data: &str, next: Option<OptBlock>, ) -> Result<Self, OptBlockError>

Create a new optional block.

§Parameters
  • id - TR-31 optional-block identifier.
  • data - ASCII optional-block data.
  • next - Optional next block in the chain.
§Errors

Returns OptBlockError::InvalidId if the identifier is unsupported.

Returns OptBlockError::NonAsciiData if the data contains non-ASCII characters.

Returns OptBlockError::BlockTooLong if the encoded block exceeds 65535 bytes.

Source

pub fn new_empty() -> Self

Create an empty optional block.

Source

pub fn new_from_str( s: &str, num_opt_blocks: usize, ) -> Result<Self, OptBlockError>

Parse one or more linked optional blocks from their string representation.

§Parameters
  • s - Encoded optional-block data.
  • num_opt_blocks - Number of linked optional blocks expected.
§Errors

Returns an OptBlockError if the input is malformed, truncated, contains invalid length information, uses an unsupported identifier, or contains non-ASCII data.

Source

pub fn export_str(&self) -> Result<String, OptBlockError>

Serialize this optional block and all following linked blocks.

§Errors

Returns OptBlockError::Uninitialized if this block does not contain a valid initialized length.

Errors from subsequent linked blocks are propagated unchanged.

Source

pub fn set_id(&mut self, id: &str) -> Result<(), OptBlockError>

Set the optional-block identifier.

§Errors

Returns OptBlockError::InvalidId if id is not a supported TR-31 optional-block identifier.

Source

pub fn id(&self) -> &str

Return the optional-block identifier.

Source

pub fn set_data(&mut self, data: &str) -> Result<(), OptBlockError>

Set the optional-block data and recalculate the encoded block length.

§Errors

Returns OptBlockError::IdNotSet if the identifier has not first been configured.

Returns OptBlockError::NonAsciiData if data contains non-ASCII characters.

Returns OptBlockError::BlockTooLong if the resulting encoded block exceeds 65535 bytes.

Source

pub fn data(&self) -> &str

Return the optional-block data.

Source

pub fn length(&self) -> &usize

Return this optional block’s encoded length.

Source

pub fn set_next(&mut self, next_block: Option<OptBlock>)

Set the next optional block.

Source

pub fn next(&self) -> Option<&OptBlock>

Return the next optional block, if one exists.

Source

pub fn append(&mut self, opt_block_to_append: OptBlock)

Append an optional block to the end of this block chain.

Source

pub fn is_allowed_id(id: &str) -> bool

Return whether an optional-block identifier is supported.

Source

pub fn total_length(&self) -> usize

Return the total encoded length of this block and all linked blocks.

Trait Implementations§

Source§

impl Clone for OptBlock

Source§

fn clone(&self) -> OptBlock

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 OptBlock

Source§

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

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

impl PartialEq for OptBlock

Source§

fn eq(&self, other: &OptBlock) -> 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 OptBlock

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.