Skip to main content

ObjectSetMethods

Trait ObjectSetMethods 

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

    // Required methods
    fn resolve_option(
        self,
        found: Option<Self::Each>,
    ) -> Result<Self::Field, EP>;
    fn debug_core(self) -> &'static str;

    // Provided methods
    fn object_set_debug(self) -> impl Debug { ... }
    fn check_label(self, label: &str) -> Result<(), EP>
       where Self::Each: ItemObjectParseable { ... }
    fn check_object_parseable(self)
       where Self::Each: ItemObjectParseable { ... }
}
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.

Source

fn debug_core(self) -> &'static str

Multiplicity representation for #[deftly(netdoc(debug))] output, core

Should generally be in a form like Option<_>.

See ItemSetMethods::debug_core and ObjectSetMethods::object_set_debug.

Provided Methods§

Source

fn object_set_debug(self) -> impl Debug

Multiplicity representation for #[deftly(netdoc(debug))] output

See ItemSetMethods::item_set_debug and ObjectSetMethods::debug_core.

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§