Skip to main content

Object

Struct Object 

Source
pub(crate) struct Object {
    members: Vec<Member>,
    inner: Trivia,
    base: String,
    unit: Indent,
}
Expand description

An object with its members in source order.

Member names are unique.

Fields§

§members: Vec<Member>§inner: Trivia

Trivia before the closing brace.

§base: String

The indent of the member that holds this object. The first member inserted into an object with no line break of its own is placed relative to it.

§unit: Indent

One level of indentation for members inserted into this object.

Implementations§

Source§

impl Object

Source

pub(in json) fn new() -> Self

Source

pub(super) fn build(entries: &Entries, dialect: Dialect, depth: usize) -> Self

The canonical object for entries, at depth.

Source

pub(in json) fn closed_by( self, inner: Trivia, ) -> Self

This object with the trivia before its closing brace.

Source

pub(super) fn indent_unit(&self) -> Option<Indent>

The indent unit of the first multi-line member, if there is one.

Source

fn detect_unit(&self, base: &str) -> Option<Indent>

The same for an object that starts a line at indent base.

Source

pub(super) fn set_unit(&mut self, unit: &Indent)

Set the indent unit for members inserted into this object.

Source

pub(in json) fn push( &mut self, member: Member, ) -> Result<(), DuplicateKey>

Append a parsed member.

§Errors

Returns the name when it is already present.

Source

fn position(&self, name: &str) -> Option<usize>

Source

pub(in json) fn keys( &self, ) -> impl Iterator<Item = &str>

The member names in source order.

Source

pub(in json) fn get( &self, name: &str, ) -> Option<&Value>

Source

pub(in json) fn descend( &mut self, name: &str, ) -> Option<&mut Value>

Enter the value of name for editing. An object value takes this object’s indent unit and the indent it is placed at, so that members inserted into it line up.

Source

pub(in json) fn insert( &mut self, name: &str, value: Value, )

Replace the value of name, or append a member.

An existing member keeps its own leading trivia, so the user’s spacing and comments stay, unless value carries a comment of its own. Then the leading trivia of value replaces it. A new member takes the leading trivia of value, moved to the indent of its siblings, and a key spelled the canonical way for the dialect it is printed in. value is laid out like a canonical member value: its lines are indented relative to the indent of its leading trivia.

An empty object stays as it is until a member is inserted into it. Then it takes a line break and the indent of the member that holds it, so that the new member and its closing brace line up.

Source

fn replace_member(&mut self, index: usize, value: Value, from: &str)

Give the member at index the body of value. from is the indent of the leading trivia of value.

Source

fn append_member( &mut self, name: &str, value: Value, from: &str, commented: bool, )

Add a member for value after the last one. from is the indent of the leading trivia of value, which has a comment when commented.

Source

fn expand_before(&mut self, index: usize)

Put the member at index on a line of its own. A one-line object is expanded to one member per line.

Source

fn expand(&mut self) -> String

Move every member to its own line and the closing brace to a line of its own. Returns the indent of the members.

Source

fn reindent_incoming(value: &mut Value, from: &str, to: &str)

Fit the body of an incoming value to its new place.

Source

fn plan_layout(&self) -> Layout

Where a new member goes.

Source

fn empty_base(&self) -> String

The indent of the line that holds the closing brace of an empty object, once it has one.

Source

fn expand_empty(&mut self)

Move the closing brace of an empty object to a line of its own.

Source

pub(in json) fn remove( &mut self, name: &str, )

Remove the member name with its leading trivia. A removed last member hands its comma style to the new last member. An object left empty prints as {} unless a comment is left inside it.

Source

pub(super) fn trivia_mut(&mut self, visit: &mut dyn FnMut(&mut Trivia))

Source

pub(super) fn write(&self, f: &mut Formatter<'_>, dialect: Dialect) -> Result

Trait Implementations§

Source§

impl Clone for Object

Source§

fn clone(&self) -> Object

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 Object

Source§

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

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

impl Eq for Object

Source§

impl PartialEq for Object

Source§

fn eq(&self, other: &Object) -> 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 Object

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, 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.