Skip to main content

Sequence

Struct Sequence 

Source
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>

Source

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.

Source

pub fn serialize(&self) -> String

Produce an EDN String from the sequence

Source

pub fn from_cbor(cbor: &[u8]) -> Result<Self, CborError>

Source

pub fn from_cbor_possibly_incomplete(cbor: &[u8]) -> Result<Self, CborError>

Parses a CBOR sequence, allowing incomplete items.

If at the end of the data there is an incomplete CBOR item, rather than producing an error, this produces ellipses wherever there is incomplete data.

let from_cbor = Sequence::from_cbor_possibly_incomplete(
    &[0x82, 0x65, 0x61, 0x62, 0x63]
).unwrap();
assert_eq!(from_cbor.serialize(), r#"["abc" + ..., ...], ..."#);
Source

pub fn to_cbor(&self) -> Result<Vec<u8>, InconsistentEdn>

Encode into a binary CBOR representation

Source

pub fn new(items: impl Iterator<Item = Item<'a>>) -> Self

Construct a CBOR sequence from items

Source

pub fn items(&self) -> impl Iterator<Item = &Item<'a>>

Access the items of the sequence

Source

pub fn items_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>>

Mutably access the items of the sequence

Source

pub fn get_items_mut(&mut self) -> impl Iterator<Item = &mut Item<'a>>

👎Deprecated:

renamed to items_mut()

Source

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.

Source

pub fn cloned<'any>(&self) -> Sequence<'any>

Clone the item, turning any Cow::Borrowed into owned versions, which can then satisfy any lifetime.

Trait Implementations§

Source§

impl<'a> Clone for Sequence<'a>

Source§

fn clone(&self) -> Sequence<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Sequence<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> PartialEq for Sequence<'a>

Source§

fn eq(&self, other: &Sequence<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Sequence<'a>

Source§

impl<'a> Transformable<'a> for Sequence<'a>

Source§

fn set_delimiters(&mut self, policy: DelimiterPolicy)

Alters how space and comments are placed inside the item. Read more
Source§

fn visit_application_literals<F>(&mut self, f: &mut F)
where F: FnMut(String, String, &mut Item<'a>) -> Result<(), String> + ?Sized,

For each item in the tree that is a single application literal, call a callback. Read more
Source§

fn visit_tag<F>(&mut self, f: &mut F)
where F: FnMut(u64, &mut Item<'a>) -> Result<(), String> + ?Sized,

For each item in the full tree (including embedded representations) that is tagged, call a callback. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Sequence<'a>

§

impl<'a> RefUnwindSafe for Sequence<'a>

§

impl<'a> Send for Sequence<'a>

§

impl<'a> Sync for Sequence<'a>

§

impl<'a> Unpin for Sequence<'a>

§

impl<'a> UnsafeUnpin for Sequence<'a>

§

impl<'a> UnwindSafe for Sequence<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.