pub struct SvcParams<Octs: ?Sized> { /* private fields */ }
Expand description
A sequence of service binding parameters.
These parameters provide information helpful when trying to connect to an
endpoint offering a service. They consist of a sequence of parameter
values. Each value has a type and some data specific to that type. The
type is provided through a u16
key with values assigned via an IANA
registry. The key and registry are available through
SvcParamKey
. Each key is only allowed
to appear at most once in the parameter sequence. Values need to be
ordered by their key’s integer value.
A value of the SvcParams
type contains a sequence of values in their
wire-format encoded form. It guarantees that this content is correctly
encoded. It does not guarantee that the content of the individual
parameter value is correct. It also does not guarantee any size limit
to the octets sequence.
You can create a value of this type through parsing or manually via
from_octets
or from_slice
.
You can also build a new value from scratch via the SvcParamsBuilder
.
The from_values
function provides a shortcut that
crates the builder, passes it to a closure, and returns the finished
parameter sequence.
Access to the values of the parameter sequence happens through a mechanism
similar to record data: Various types exist that implement either a
specific value type or a group of types. These types need to implement the
SvcParamValue
and ParseSvcParamValue
traits to be used to access
values. They can be used as a type parameter to the iter
method to acquire an iterator over all the values that they understand.
Since every concrete value can only be present once, the
first
method can be used together with a value type
implementing that concrete value to get the value if present. As a
convenience, methods exist for every currently defined value type which
return a value of that type if present.
The type UnknownSvcParam
can be used to represent any value type with
the value as a octets sequence. The AllValues
enum provides typed
access to all known value types.
§Wire Format
The wire format of a parameter sequence consists of a sequence of
values. Each value is encoded as a 16 bit parameter key – represented
by SvcParamKey
in this crate –,
followed by an unsigned 16 bit length value, followed by this many
octets. Since the sequence is the last element in the record data, it
is limited by the length of the record data only.
Implementations§
source§impl<Octs: Octets + ?Sized> SvcParams<Octs>
impl<Octs: Octets + ?Sized> SvcParams<Octs>
sourcepub fn no_default_alpn(&self) -> bool
pub fn no_default_alpn(&self) -> bool
Returns whether the NoDefaultAlpn
value is present.
source§impl<Octs> SvcParams<Octs>
impl<Octs> SvcParams<Octs>
sourcepub fn from_octets(octets: Octs) -> Result<Self, SvcParamsError>
pub fn from_octets(octets: Octs) -> Result<Self, SvcParamsError>
Creates a parameter sequence from an octets sequence.
The method checks that octets
contains a parameter sequence that is
correctly encoded in wire format. It does not check that the
individual values are correctly encoded. It also does not check for
any length limit.
sourcepub unsafe fn from_octets_unchecked(octets: Octs) -> Self
pub unsafe fn from_octets_unchecked(octets: Octs) -> Self
Creates a new value from an octets sequence without checking.
§Safety
The caller has to ensure that octets
contains a properly formatted
parameter sequence.
source§impl SvcParams<[u8]>
impl SvcParams<[u8]>
sourcepub fn from_slice(slice: &[u8]) -> Result<&Self, SvcParamsError>
pub fn from_slice(slice: &[u8]) -> Result<&Self, SvcParamsError>
Creates a parameter sequence from an octets slice.
The method checks that slice
contains a parameter sequence that is
correctly encoded in wire format. It does not check that the
individual values are correctly encoded. It also does not check for
any length limit.
sourcepub unsafe fn from_slice_unchecked(slice: &[u8]) -> &Self
pub unsafe fn from_slice_unchecked(slice: &[u8]) -> &Self
Creates a new value from a slice without checking.
§Safety
The caller has to ensure that slice
contains a properly formatted
parameter sequence.
source§impl<Octs> SvcParams<Octs>
impl<Octs> SvcParams<Octs>
sourcepub fn from_values<F>(op: F) -> Result<Self, PushError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: AsRef<[u8]> + OctetsBuilder + EmptyBuilder,
F: FnOnce(&mut SvcParamsBuilder<<Octs as FromBuilder>::Builder>) -> Result<(), PushError>,
pub fn from_values<F>(op: F) -> Result<Self, PushError>where
Octs: FromBuilder,
<Octs as FromBuilder>::Builder: AsRef<[u8]> + OctetsBuilder + EmptyBuilder,
F: FnOnce(&mut SvcParamsBuilder<<Octs as FromBuilder>::Builder>) -> Result<(), PushError>,
Creates a parameter sequence by constructing it from values.
The method expects a closure that receives an SvcParamsBuilder
which it should push all the required values to. Once it returns,
this builder is frozen into an SvcParams
value and returned.
source§impl<Octs: AsRef<[u8]> + ?Sized> SvcParams<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> SvcParams<Octs>
sourcepub fn for_slice(&self) -> &SvcParams<[u8]>
pub fn for_slice(&self) -> &SvcParams<[u8]>
Returns a parameter sequence atop a slice of this value’s octets.
sourcepub fn first<'s, Value>(&'s self) -> Option<Value>where
Octs: Octets,
Value: ParseSvcParamValue<'s, Octs>,
pub fn first<'s, Value>(&'s self) -> Option<Value>where
Octs: Octets,
Value: ParseSvcParamValue<'s, Octs>,
Returns the first value of type Value
.
This method is intended to be used with value types implementing a
specific type. Since only one instance is allowed to be present,
this method also returns None
if the first value fails parsing,
assuming that the value is unusable and should be ignored.
This may not be the correct behaviour in all cases. Please use
self.iter::<Value>().next()
to get an optional parsing result.
sourcepub fn iter<Value>(&self) -> ValueIter<'_, Octs, Value> ⓘ
pub fn iter<Value>(&self) -> ValueIter<'_, Octs, Value> ⓘ
Returns an iterator over all values accepted by Value
.
sourcepub fn iter_all(&self) -> ValueIter<'_, Octs, AllValues<Octs>> ⓘwhere
Octs: Sized,
pub fn iter_all(&self) -> ValueIter<'_, Octs, AllValues<Octs>> ⓘwhere
Octs: Sized,
Returns an iterator over all values.
sourcepub fn iter_raw(&self) -> impl Iterator<Item = UnknownSvcParam<Octs::Range<'_>>>
pub fn iter_raw(&self) -> impl Iterator<Item = UnknownSvcParam<Octs::Range<'_>>>
Returns an iterator over all values in their raw form.
sourcepub fn compose<Target: OctetsBuilder + ?Sized>(
&self,
target: &mut Target,
) -> Result<(), Target::AppendError>
pub fn compose<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
Composes the wire-format of the parameter sequence.
Trait Implementations§
source§impl<SrcOcts, Octs> OctetsFrom<SvcParams<SrcOcts>> for SvcParams<Octs>where
Octs: OctetsFrom<SrcOcts>,
impl<SrcOcts, Octs> OctetsFrom<SvcParams<SrcOcts>> for SvcParams<Octs>where
Octs: OctetsFrom<SrcOcts>,
type Error = <Octs as OctetsFrom<SrcOcts>>::Error
source§impl<Octs, OtherOcts> PartialOrd<SvcParams<OtherOcts>> for SvcParams<Octs>
impl<Octs, OtherOcts> PartialOrd<SvcParams<OtherOcts>> for SvcParams<Octs>
impl<Octs: AsRef<[u8]> + ?Sized> Eq for SvcParams<Octs>
Auto Trait Implementations§
impl<Octs> Freeze for SvcParams<Octs>
impl<Octs> RefUnwindSafe for SvcParams<Octs>where
Octs: RefUnwindSafe + ?Sized,
impl<Octs> Send for SvcParams<Octs>
impl<Octs> Sync for SvcParams<Octs>
impl<Octs> Unpin for SvcParams<Octs>
impl<Octs> UnwindSafe for SvcParams<Octs>where
Octs: UnwindSafe + ?Sized,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)