Skip to main content

Mapping

Struct Mapping 

Source
pub(crate) struct Mapping {
    shape: Shape,
    entries: Vec<Entry>,
    indent: usize,
    step: usize,
}
Expand description

A mapping whose entries can be listed, replaced, appended, and removed.

Fields§

§shape: Shape§entries: Vec<Entry>§indent: usize§step: usize

Implementations§

Source§

impl Mapping

Source

pub(super) const fn block( opening: Text, entries: Vec<Entry>, indent: usize, step: usize, ) -> Self

A block mapping whose keys sit at indent, with nested mappings step columns deeper.

Source

pub(super) const fn empty_flow( before: Text, braces: Text, after: Text, indent: usize, step: usize, ) -> Self

An empty flow mapping whose block entries will sit at indent.

Source

pub(super) fn reopened(self, opening: Text, indent: usize, step: usize) -> Self

This mapping opened by opening, with its keys moved to indent and nested mappings step columns deeper.

Source

pub(super) fn take_header(&mut self) -> Text

Split off the leading text of the first entry, except for the comment block directly above its key.

Source

pub(crate) fn keys(&self) -> impl Iterator<Item = &str>

Source

pub(crate) fn get(&self, key: &str) -> Option<&Entry>

Source

pub(crate) fn get_mut(&mut self, key: &str) -> Option<&mut Entry>

Source

pub(crate) fn insert(&mut self, entry: Entry)

Put entry in the mapping, laid out at this mapping’s indent and step.

An entry with the same key is replaced in place. It keeps the existing key text, trailing comment of a plain value, and leading text unless the new entry brings a comment. Any other entry is appended.

Source

pub(crate) fn remove(&mut self, key: &str)

Remove the entry with key, together with its leading text. A mapping left without entries becomes {}.

Source

pub(super) fn comment(&self) -> Option<&str>

The comment on the key line, with the whitespace before it.

Source

pub(super) fn keep_comment(&mut self, comment: &str)

Put comment on the key line unless it has one.

Source

const fn key_line(&self) -> &Text

What follows the owning key on its line.

Source

const fn key_line_mut(&mut self) -> &mut Text

Source

pub(super) fn collapse(&mut self)

Turn an emptied block mapping into {}, as an empty value would read back as null. Anchors and a trailing comment stay.

Source

fn reindent_to(&mut self, indent: usize, step: usize)

Move the keys to indent and nested mappings to step columns per level, carrying every entry’s lines along.

Source

pub(super) fn terminate(&mut self)

Make the last line of the mapping end with a line break.

Source

fn expand(&mut self)

Turn an empty flow mapping into a block mapping, keeping what surrounds it.

The line holding the braces stays when something else is on it, such as a key or a --- marker. A bare {} line disappears. A comment after the closing brace moves up to the key’s line.

Trait Implementations§

Source§

impl Clone for Mapping

Source§

fn clone(&self) -> Mapping

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 Debug for Mapping

Source§

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

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

impl Display for Mapping

Source§

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

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

impl Eq for Mapping

Source§

impl PartialEq for Mapping

Source§

fn eq(&self, other: &Mapping) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mapping

Auto Trait Implementations§

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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, <T as TryFrom<U>>::Error>

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.