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: TriviaTrivia before the closing brace.
base: StringThe 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: IndentOne level of indentation for members inserted into this object.
Implementations§
Source§impl Object
impl Object
pub(in json) fn new() -> Self
Sourcepub(super) fn build(entries: &Entries, dialect: Dialect, depth: usize) -> Self
pub(super) fn build(entries: &Entries, dialect: Dialect, depth: usize) -> Self
The canonical object for entries, at depth.
Sourcepub(in json) fn closed_by(
self,
inner: Trivia,
) -> Self
pub(in json) fn closed_by( self, inner: Trivia, ) -> Self
This object with the trivia before its closing brace.
Sourcepub(super) fn indent_unit(&self) -> Option<Indent>
pub(super) fn indent_unit(&self) -> Option<Indent>
The indent unit of the first multi-line member, if there is one.
Sourcefn detect_unit(&self, base: &str) -> Option<Indent>
fn detect_unit(&self, base: &str) -> Option<Indent>
The same for an object that starts a line at indent base.
Sourcepub(super) fn set_unit(&mut self, unit: &Indent)
pub(super) fn set_unit(&mut self, unit: &Indent)
Set the indent unit for members inserted into this object.
fn position(&self, name: &str) -> Option<usize>
pub(in json) fn get( &self, name: &str, ) -> Option<&Value>
Sourcepub(in json) fn descend(
&mut self,
name: &str,
) -> Option<&mut Value>
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.
Sourcepub(in json) fn insert(
&mut self,
name: &str,
value: Value,
)
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.
Sourcefn replace_member(&mut self, index: usize, value: Value, from: &str)
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.
Sourcefn append_member(
&mut self,
name: &str,
value: Value,
from: &str,
commented: bool,
)
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.
Sourcefn expand_before(&mut self, index: usize)
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.
Sourcefn expand(&mut self) -> String
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.
Sourcefn reindent_incoming(value: &mut Value, from: &str, to: &str)
fn reindent_incoming(value: &mut Value, from: &str, to: &str)
Fit the body of an incoming value to its new place.
Sourcefn plan_layout(&self) -> Layout
fn plan_layout(&self) -> Layout
Where a new member goes.
Sourcefn empty_base(&self) -> String
fn empty_base(&self) -> String
The indent of the line that holds the closing brace of an empty object, once it has one.
Sourcefn expand_empty(&mut self)
fn expand_empty(&mut self)
Move the closing brace of an empty object to a line of its own.
Sourcepub(in json) fn remove(
&mut self,
name: &str,
)
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.
pub(super) fn trivia_mut(&mut self, visit: &mut dyn FnMut(&mut Trivia))
pub(super) fn write(&self, f: &mut Formatter<'_>, dialect: Dialect) -> Result
Trait Implementations§
impl Eq for Object
impl StructuralPartialEq for Object
Auto Trait Implementations§
impl Freeze for Object
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnsafeUnpin for Object
impl UnwindSafe for Object
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.