Skip to main content

Doc

Struct Doc 

Source
pub struct Doc<'a> { /* private fields */ }
Expand description

A value with the key table its keys are interned against.

Everything a Value offers is here too, and the things that need a name rather than an id, which are a lookup, a walk over the members and printing the thing, go through the table. A document whose keys are bytes works the same way and simply never asks the table anything, so a caller does not have to know which kind it is holding.

Implementations§

Source§

impl<'a> Doc<'a>

Source

pub fn new(value: Value<'a>, keys: &'a Keys) -> Doc<'a>

A view of value against keys.

Source

pub fn value(&self) -> Value<'a>

The value underneath, for the accessors that never need a name.

Source

pub fn keys(&self) -> &'a Keys

The key table this reads names out of.

Source

pub fn kind(&self) -> Kind

What this value is.

Source

pub fn is_null(&self) -> bool

Whether this is null.

Source

pub fn as_bool(&self) -> Option<bool>

The boolean this holds, if it holds one.

Source

pub fn as_int(&self) -> Option<i64>

The integer this holds, if it holds one.

Source

pub fn as_float(&self) -> Option<f64>

The float this holds, if it holds one.

Source

pub fn as_text(&self) -> Option<&'a str>

The string this holds, if it holds one and it is UTF-8.

Source

pub fn text_bytes(&self) -> Option<&'a [u8]>

The string this holds as it is stored, without the UTF-8 check.

Source

pub fn len(&self) -> usize

How many elements a container holds. Zero for anything else.

Source

pub fn is_empty(&self) -> bool

Whether this is a container with nothing in it.

Source

pub fn get(&self, key: &[u8]) -> Option<Doc<'a>>

The value stored under key.

For an interned object this is a name to id lookup in the table and then a binary search over integers. A name the table has never seen cannot be in the document, so it answers None without touching the document at all.

Source

pub fn at(&self, i: usize) -> Option<Doc<'a>>

Element i of a container, in the container’s own order.

Source

pub fn key_at(&self, i: usize) -> Option<&'a [u8]>

The name of member i of an object, whichever way the keys are stored.

Source

pub fn members(&self) -> DocMembers<'a>

Every member of an object, name first, in the order the document stores them.

That order is by key id for an interned object and by key bytes for one whose keys are bytes, so it is stable for a given collection and it is not alphabetical. Sort it if the order is part of the answer.

Source

pub fn iter(&self) -> DocElems<'a>

Every element of a container, in the container’s own order.

Source

pub fn path(&self, path: &str) -> Result<Option<Doc<'a>>>

The value at path, where a path names exactly one place.

The same grammar Value::path takes, with the names resolved through the key table on the way down.

Source

pub fn path_bytes(&self, path: &[u8]) -> Result<Option<Doc<'a>>>

Doc::path for a path that is already bytes.

Trait Implementations§

Source§

impl<'a> Clone for Doc<'a>

Source§

fn clone(&self) -> Doc<'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> Copy for Doc<'a>

Source§

impl Debug for Doc<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Doc<'a>

§

impl<'a> RefUnwindSafe for Doc<'a>

§

impl<'a> Send for Doc<'a>

§

impl<'a> Sync for Doc<'a>

§

impl<'a> Unpin for Doc<'a>

§

impl<'a> UnsafeUnpin for Doc<'a>

§

impl<'a> UnwindSafe for Doc<'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.