pub struct OwnedFields { /* private fields */ }Expand description
A remainder that owns its fields, for keeping the fields a section does not take beyond the lifetime of the input, in order.
Use a Vec<FieldRef> instead to borrow them without copying. A section interprets owned fields by reference, keeping their original positions:
use base_message::{FieldSection, FieldType, FieldValueError, OwnedFields, ascii_text, combination::Singleton};
struct Text(String);
impl FieldType<'_> for Text {
type Combination = Singleton;
fn parse(value: &[u8]) -> Result<Self, FieldValueError> {
Ok(Self(ascii_text(value)?.to_owned()))
}
}
#[derive(FieldSection)]
struct Transport {
#[field("host")]
host: Text,
}
#[derive(FieldSection)]
struct Application {
#[field("x-request-id")]
request_id: Option<Text>,
}
let (_, rest): (Transport, OwnedFields) = Transport::partition([("Host", "example.com"), ("X-Request-Id", "abc")])?;
let application = Application::interpret(&rest)?;
assert_eq!(application.request_id.map(|id| id.0).as_deref(), Some("abc"));Implementations§
Source§impl OwnedFields
impl OwnedFields
Sourcepub fn iter(&self) -> Iter<'_, OwnedField> ⓘ
pub fn iter(&self) -> Iter<'_, OwnedField> ⓘ
The fields, in order.
Sourcepub fn as_slice(&self) -> &[OwnedField]
pub fn as_slice(&self) -> &[OwnedField]
The fields, in order, as a slice.
Trait Implementations§
Source§impl Clone for OwnedFields
impl Clone for OwnedFields
Source§impl Debug for OwnedFields
impl Debug for OwnedFields
Source§impl Default for OwnedFields
impl Default for OwnedFields
impl Eq for OwnedFields
Source§impl<'a> Extend<FieldRef<'a>> for OwnedFields
impl<'a> Extend<FieldRef<'a>> for OwnedFields
Source§fn extend<I: IntoIterator<Item = FieldRef<'a>>>(&mut self, fields: I)
fn extend<I: IntoIterator<Item = FieldRef<'a>>>(&mut self, fields: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<'a> FromIterator<FieldRef<'a>> for OwnedFields
impl<'a> FromIterator<FieldRef<'a>> for OwnedFields
Source§impl Hash for OwnedFields
impl Hash for OwnedFields
Source§impl<'a> IntoIterator for &'a OwnedFields
impl<'a> IntoIterator for &'a OwnedFields
Source§impl IntoIterator for OwnedFields
impl IntoIterator for OwnedFields
Source§impl PartialEq for OwnedFields
impl PartialEq for OwnedFields
impl StructuralPartialEq for OwnedFields
Auto Trait Implementations§
impl Forget for OwnedFields
impl Freeze for OwnedFields
impl RefUnwindSafe for OwnedFields
impl Send for OwnedFields
impl Sync for OwnedFields
impl Unpin for OwnedFields
impl UnsafeUnpin for OwnedFields
impl UnwindSafe for OwnedFields
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
Mutably borrows from an owned value. Read more