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
impl OptBlock
Sourcepub fn new(
id: &str,
data: &str,
next: Option<OptBlock>,
) -> Result<Self, OptBlockError>
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.
Sourcepub fn new_from_str(
s: &str,
num_opt_blocks: usize,
) -> Result<Self, OptBlockError>
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.
Sourcepub fn export_str(&self) -> Result<String, OptBlockError>
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.
Sourcepub fn set_id(&mut self, id: &str) -> Result<(), OptBlockError>
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.
Sourcepub fn set_data(&mut self, data: &str) -> Result<(), OptBlockError>
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.
Sourcepub fn append(&mut self, opt_block_to_append: OptBlock)
pub fn append(&mut self, opt_block_to_append: OptBlock)
Append an optional block to the end of this block chain.
Sourcepub fn is_allowed_id(id: &str) -> bool
pub fn is_allowed_id(id: &str) -> bool
Return whether an optional-block identifier is supported.
Sourcepub fn total_length(&self) -> usize
pub fn total_length(&self) -> usize
Return the total encoded length of this block and all linked blocks.