ObjectSetMethods

Trait ObjectSetMethods 

Source
pub trait ObjectSetMethods: Copy + Sized {
    type Each: Sized;
    type Field: Sized;

    // Required method
    fn resolve_option(
        self,
        found: Option<Self::Each>,
    ) -> Result<Self::Field, EP>;

    // Provided methods
    fn check_label(self, label: &str) -> Result<(), EP>
       where Self::Each: ItemObjectParseable { ... }
    fn check_object_parseable(self)
       where Self::Each: ItemObjectParseable { ... }
}
Available on crate feature parse2 only.
Expand description

Method for handling some multiplicity of Objects

For use by macros.

See the module-level docs, and Field type in ItemValueParseable.

§Example

The code in the (derive) macro output is roughly like this:

use tor_netdoc::parse2::multiplicity::{MultiplicitySelector, ObjectSetMethods as _};
use tor_netdoc::parse2::{ItemStream, ParseInput};
let doc = "intro-item\n-----BEGIN OBJECT-----\naGVsbG8=\n-----END OBJECT-----\n";
let input = ParseInput::new(doc, "<literal>");
let mut items = ItemStream::new(&input).unwrap();
let mut item = items.next().unwrap().unwrap();

let selector = MultiplicitySelector::<Option<String>>::default();
let obj = item.object().map(|obj| {
    let data = obj.decode_data().unwrap();
    String::from_utf8(data)
}).transpose().unwrap();
let obj = selector.resolve_option(obj).unwrap();
assert_eq!(obj, Some("hello".to_owned()));

Required Associated Types§

Source

type Each: Sized

The value for each Item.

Source

type Field: Sized

The output type: the type of the field in the Item struct.

Required Methods§

Source

fn resolve_option(self, found: Option<Self::Each>) -> Result<Self::Field, EP>

Parse zero or more argument(s) into Self::Field.

Provided Methods§

Source

fn check_label(self, label: &str) -> Result<(), EP>

If the contained type is ItemObjectParseable, call its check_label

Source

fn check_object_parseable(self)

Check that the contained type can be parsed as an object

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§