pub trait ItemSetMethods: Copy + Sized {
type Each: Sized;
type Field: Sized;
// Required methods
fn can_accumulate(self, acc: &Option<Self::Field>) -> Result<(), EP>;
fn accumulate(
self,
acc: &mut Option<Self::Field>,
one: Self::Each,
) -> Result<(), EP>;
fn debug_core(self) -> &'static str;
fn finish(
self,
acc: Option<Self::Field>,
item_keyword: &'static str,
) -> Result<Self::Field, EP>;
// Provided methods
fn item_set_debug(self) -> impl Debug { ... }
fn is_intro_item_keyword(self, kw: KeywordRef<'_>) -> bool
where Self::Each: NetdocParseable { ... }
fn is_structural_keyword(self, kw: KeywordRef<'_>) -> Option<IsStructural>
where Self::Each: NetdocParseable { ... }
fn finish_subdoc(self, acc: Option<Self::Field>) -> Result<Self::Field, EP>
where Self::Each: NetdocParseable { ... }
fn check_item_value_parseable(self)
where Self::Each: ItemValueParseable { ... }
fn check_signature_item_parseable<H>(self, _: &mut H)
where Self::Each: SignatureItemParseable,
H: AsMut<<Self::Each as SignatureItemParseable>::HashAccu> { ... }
fn check_subdoc_parseable(self)
where Self::Each: NetdocParseable { ... }
fn check_item_argument_parseable(self)
where Self::Each: ItemArgumentParseable { ... }
}Expand description
Methods for handling some multiplicity of Items, during parsing
For use by macros.
During parsing, we accumulate into a value of type Option<Self::Field>.
The semantics of this are item-set-implementation-dependent;
using a type which is generic over the field type in a simple way
allows the partially-parsed accumulation state for a whole netdoc to have a concrete type.
See the module-level docs, and
Field type in NetdocParseable.
§Example
The code in the (derive) macro output is roughly like this:
use tor_netdoc::parse2::multiplicity::{MultiplicitySelector, ItemSetMethods as _};
let selector = MultiplicitySelector::<Vec<i32>>::default();
let mut accum = None;
selector.accumulate(&mut accum, 12).unwrap();
let out = selector.finish(accum, "item-set").unwrap();
assert_eq!(out, [12]);Required Associated Types§
Required Methods§
Sourcefn can_accumulate(self, acc: &Option<Self::Field>) -> Result<(), EP>
fn can_accumulate(self, acc: &Option<Self::Field>) -> Result<(), EP>
Can we accumulate another item ?
Can be used to help predict whether accumulate will throw.
Sourcefn accumulate(
self,
acc: &mut Option<Self::Field>,
one: Self::Each,
) -> Result<(), EP>
fn accumulate( self, acc: &mut Option<Self::Field>, one: Self::Each, ) -> Result<(), EP>
Accumulate one value into the accumulator.
Sourcefn debug_core(self) -> &'static str
fn debug_core(self) -> &'static str
Multiplicity representation for #[deftly(netdoc(debug))] output, core
Should generally be in a form like Vec<_>.
See also ItemSetMethods::item_set_debug, which is what the derives call.
Provided Methods§
Sourcefn item_set_debug(self) -> impl Debug
fn item_set_debug(self) -> impl Debug
Multiplicity representation for #[deftly(netdoc(debug))] output
This adds a bit framing and type-fu that allows the derive macro’s call to be as simple as possible.
See also ItemSetMethods::debug_core, which is what each multiplicity implements.
Sourcefn is_intro_item_keyword(self, kw: KeywordRef<'_>) -> boolwhere
Self::Each: NetdocParseable,
fn is_intro_item_keyword(self, kw: KeywordRef<'_>) -> boolwhere
Self::Each: NetdocParseable,
If the contained type is a sub-document, call its is_intro_item_keyword.
Sourcefn is_structural_keyword(self, kw: KeywordRef<'_>) -> Option<IsStructural>where
Self::Each: NetdocParseable,
fn is_structural_keyword(self, kw: KeywordRef<'_>) -> Option<IsStructural>where
Self::Each: NetdocParseable,
If the contained type is a sub-document, call its is_structural_keyword.
Sourcefn finish_subdoc(self, acc: Option<Self::Field>) -> Result<Self::Field, EP>where
Self::Each: NetdocParseable,
fn finish_subdoc(self, acc: Option<Self::Field>) -> Result<Self::Field, EP>where
Self::Each: NetdocParseable,
finish for if the contained type is a wsub-document
Obtain the sub-document’s intro keyword from its doctype_for_error.
Sourcefn check_item_value_parseable(self)where
Self::Each: ItemValueParseable,
fn check_item_value_parseable(self)where
Self::Each: ItemValueParseable,
Check that the element type is an Item
For providing better error messages when struct fields don’t implement the right trait.
See derive.rs, and search for this method name.
Sourcefn check_signature_item_parseable<H>(self, _: &mut H)where
Self::Each: SignatureItemParseable,
H: AsMut<<Self::Each as SignatureItemParseable>::HashAccu>,
fn check_signature_item_parseable<H>(self, _: &mut H)where
Self::Each: SignatureItemParseable,
H: AsMut<<Self::Each as SignatureItemParseable>::HashAccu>,
Check that the element type is a Signature
Sourcefn check_subdoc_parseable(self)where
Self::Each: NetdocParseable,
fn check_subdoc_parseable(self)where
Self::Each: NetdocParseable,
Check that the element type is a sub-document
Sourcefn check_item_argument_parseable(self)where
Self::Each: ItemArgumentParseable,
fn check_item_argument_parseable(self)where
Self::Each: ItemArgumentParseable,
Check that the element type is an argument
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.