pub struct OptionView<'a>(/* private fields */);Expand description
Zero-copy view into a variable-length SD option in a buffer.
Wire layout:
[0..2]: length (u16 BE) =total_size- 3[2]: option type (u8)[3]: reserved/discard flag (u8)[4..]: type-specific data
Implementations§
Source§impl<'a> OptionView<'a>
impl<'a> OptionView<'a>
Sourcepub fn option_type(&self) -> Result<OptionType, Error>
pub fn option_type(&self) -> Result<OptionType, Error>
Sourcepub fn wire_size(&self) -> usize
pub fn wire_size(&self) -> usize
Total wire size of this option (length field value + OPTION_LENGTH_SIZE_DELTA).
Sourcepub fn as_ipv4(&self) -> Result<(Ipv4Addr, TransportProtocol, u16), Error>
pub fn as_ipv4(&self) -> Result<(Ipv4Addr, TransportProtocol, u16), Error>
Parse as IPv4 endpoint/multicast/SD option.
Returns (ip, protocol, port).
§Errors
Returns Error::InvalidOptionTransportProtocol if the protocol byte is unrecognized.
Views obtained via SdHeaderView::parse have already
had their protocol byte validated, so this error cannot occur for those callers —
it is retained only to keep the API usable if an OptionView is ever constructed
outside the validated parse path.
Sourcepub fn as_ipv6(&self) -> Result<(Ipv6Addr, TransportProtocol, u16), Error>
pub fn as_ipv6(&self) -> Result<(Ipv6Addr, TransportProtocol, u16), Error>
Parse as IPv6 endpoint/multicast/SD option.
Returns (ip, protocol, port).
§Errors
Returns Error::InvalidOptionTransportProtocol if the protocol byte is unrecognized.
Views obtained via SdHeaderView::parse have already
had their protocol byte validated, so this error cannot occur for those callers —
it is retained only to keep the API usable if an OptionView is ever constructed
outside the validated parse path.
Sourcepub fn configuration_bytes(&self) -> &'a [u8] ⓘ
pub fn configuration_bytes(&self) -> &'a [u8] ⓘ
Raw configuration bytes (for Configuration options).
Sourcepub fn as_load_balancing(&self) -> Result<(u16, u16), Error>
pub fn as_load_balancing(&self) -> Result<(u16, u16), Error>
Parse as load-balancing option. Returns (priority, weight).
§Errors
Currently always succeeds; the Result return type is reserved for future validation.
Sourcepub fn to_owned(&self) -> Result<Options, Error>
pub fn to_owned(&self) -> Result<Options, Error>
Converts this view into an owned Options.
§Errors
Returns an error if the option type is unrecognized, the transport protocol byte
is invalid, or the configuration string exceeds MAX_CONFIGURATION_STRING_LENGTH.
§Panics
Panics if a configuration string passes the length check but fails to fit into the heapless buffer (unreachable in practice).
Trait Implementations§
Source§impl<'a> Clone for OptionView<'a>
impl<'a> Clone for OptionView<'a>
Source§fn clone(&self) -> OptionView<'a>
fn clone(&self) -> OptionView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'a> Copy for OptionView<'a>
Source§impl<'a> Debug for OptionView<'a>
impl<'a> Debug for OptionView<'a>
Source§impl<'a> Decode<'a> for OptionView<'a>
impl<'a> Decode<'a> for OptionView<'a>
Source§fn decode(buf: &'a [u8]) -> Result<(Self, &'a [u8]), Self::Error>
fn decode(buf: &'a [u8]) -> Result<(Self, &'a [u8]), Self::Error>
Decode a single variable-length SD option from the front of buf.
The stride comes from the option’s 2-byte length field. This slices
only; it does NOT validate the option type, per-type length, or
transport-protocol byte. Validation is deferred to the accessors
(option_type / as_ipv4 / to_owned) — the L2 validation pass —
keeping this a lazy zero-copy view.
§Errors
Returns Incomplete if fewer than
the fixed option header remains, or if the declared wire size exceeds
the remaining bytes, and
IncorrectOptionsSize if the declared
wire size is smaller than the option header itself.
Source§type Error = Error
type Error = Error
Incomplete and TrailingBytes
so the fixed-width leaf read helpers (read_u8, read_u16_be,
read_array, …) and the decode_exact default lift through ?. Read moreSource§impl<'a> DecodeIter<'a> for OptionView<'a>
impl<'a> DecodeIter<'a> for OptionView<'a>
Source§fn decode_next(buf: &'a [u8]) -> Result<Option<(Self, &'a [u8])>, Self::Error>
fn decode_next(buf: &'a [u8]) -> Result<Option<(Self, &'a [u8])>, Self::Error>
Decode the next option, or Ok(None) at a clean end of buffer.
A partial/truncated trailing option after a good start is surfaced as an
Err rather than silently dropped.
§Errors
Returns Incomplete if a partial
option remains after a good start.
Source§type Error = Error
type Error = Error
Incomplete so the
fixed-width leaf read helpers lift through ?. As with
Decode::Error, the variable-width helpers return
ReadUintError and need their own From impl.