pub struct Sequence<'a> { /* private fields */ }Expand description
A CBOR Sequence.
Typical actions on this are the same as on StandaloneItem, but it can process multiple CBOR
items in a row, and thus offers interaction with all those items:
let from_edn = Sequence::parse("
1
2
3
").unwrap();
assert_eq!(from_edn.items().count(), 3);Implementations§
Source§impl<'a> Sequence<'a>
impl<'a> Sequence<'a>
Sourcepub fn parse(s: &'a str) -> Result<Self, ParseError>
pub fn parse(s: &'a str) -> Result<Self, ParseError>
Ingests CBOR Diagnostic Notation (EDN) representing a CBOR sequence
Note that this will only return syntactic errors. Content errors that make it impossible to produce this as CBOR, such as non-matching encoding indicators or unknown application oriented literals, are not reported.
pub fn from_cbor(cbor: &[u8]) -> Result<Self, CborError>
Sourcepub fn to_cbor(&self) -> Result<Vec<u8>, InconsistentEdn>
pub fn to_cbor(&self) -> Result<Vec<u8>, InconsistentEdn>
Encode into a binary CBOR representation
Sourcepub fn visit_application_literals<F, RF>(&mut self, f: RF)
pub fn visit_application_literals<F, RF>(&mut self, f: RF)
For each item in the tree that is any element of the squence, call a callback.
This is primarily used to apply custom EDN filtering:
let mut full = Sequence::parse("0 /unmodified/, german'zweiundvierzig'").unwrap();
full.visit_application_literals(&mut |id, value: String, item: &mut cbor_edn::Item| {
if id == "german" {
let numeric = match value.as_str() {
"dreiundzwanzig" => 23,
"zweiundvierzig" => 42,
_ => todo!(),
};
*item = Item::new_integer_decimal(numeric).into();
}
Ok(())
});
assert_eq!(full.serialize(), "0 /unmodified/, 42");Sourcepub fn visit_tag<F, RF>(&mut self, f: RF)
pub fn visit_tag<F, RF>(&mut self, f: RF)
For each item in the full tree of any element (including embedded representations) that is tagged, call a callback.
Any error string is placed in a comment next to the item. The function should return Ok(()) on any tags it is not interested in visiting.
This is primarily used to apply custom EDN application; see application::dt_tag_to_aol for an example.
Sourcepub fn items_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>>
pub fn items_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>>
Mutably access the items of the sequence
pub fn get_items_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>>
renamed to items_mut()
Sourcepub fn discard_encoding_indicators(&mut self)
pub fn discard_encoding_indicators(&mut self)
Removes any encoding indicators present in the sequence.
This does not affect space or comments; in particular, an item containing only the necessary space may be left with extraneous (but harmless) space that was previously needed to set an encoding indicator apart from a value.
Sourcepub fn set_delimiters(&mut self, policy: DelimiterPolicy)
pub fn set_delimiters(&mut self, policy: DelimiterPolicy)
Alters how space and comments are placed inside the sequence.
See the policy values for details.
Sourcepub fn cloned<'any>(&self) -> Sequence<'any>
pub fn cloned<'any>(&self) -> Sequence<'any>
Clone the item, turning any Cow::Borrowed into owned versions, which can then satisfy
any lifetime.