Struct jupiter::ig::docs::Doc

source ·
pub struct Doc { /* private fields */ }
Expand description

Provides the root node of an information graph.

This essentially bundles the SymbolTable and the root node of the graph.

Note that a Doc cannot be modified once it has been built which permits to use a very efficient memory layout and also permits to cache queries, lookup indices and query results as provided by Table.

Implementations§

source§

impl Doc

source

pub fn empty() -> Self

Creates an entirely empty doc which can be used as a fallback or placeholder.

source

pub fn new(symbols: SymbolTable, root: Node) -> Self

Creates a new document by combining the given SymbolTable and Node.

Note that this is mainly an internal API as DocBuilder should be used to generate new docs.

source

pub fn root(&self) -> Element<'_>

Returns the root node of this doc which is either a list or a map.

§Example
let builder = DocBuilder::new();
let mut list_builder = builder.list();
list_builder.append_int(1);
let doc = builder.build_list(list_builder);

let root = doc.root();

assert_eq!(root.len(), 1)
source

pub fn compile(&self, query: impl AsRef<str>) -> Query

Compiles the given query.

A query is composed of a chain of keys separated by “.”. For nested objects, we apply one key after another to obtain the resulting target element.

Note that “.” represents an identity query which returns the element itself.

§Example
let builder = DocBuilder::new();
let mut object_builder = builder.obj();
let mut inner_builder = builder.obj();
inner_builder.put_int("Bar", 42).unwrap();
object_builder.put_object("Foo", inner_builder).unwrap();
let doc = builder.build_object(object_builder);

let query = doc.compile("Foo.Bar");
assert_eq!(query.execute(doc.root()).as_int().unwrap(), 42);

let query = doc.compile(".");
assert!(query.execute(doc.root()).is_object());
§Performance

Compiling queries is rather fast, therefore ad-hoc queries can be executed using Element::query. Pre-compiled queries are only feasible if a query is known to be executed several times (e.g. when iterating over a list of objects and executing the same query each time).

Also note that if we encounter an unknown symbol here, we know that the query cannot be fulfilled and therefore return an empty query here which always yields and empty result without any actual work being done.

source

pub fn symbols_mut(&mut self) -> &mut SymbolTable

Provides mutable access on the underlying symbol table.

source

pub fn symbols(&self) -> &SymbolTable

Provides readonly access on the symbol table.

source

pub fn allocated_size(&self) -> usize

Estimates the size (in bytes) occupied by this doc.

This accounts for both, the SymbolTable and the actual information graph. Note that this is an approximation as not all data structures reveal their true size.

§Example
let builder = DocBuilder::new();
let mut object_builder = builder.obj();
let mut inner_builder = builder.obj();
inner_builder.put_int("Bar", 42).unwrap();
object_builder.put_object("Foo", inner_builder).unwrap();
let doc = builder.build_object(object_builder);

println!("{}", doc.allocated_size());

Auto Trait Implementations§

§

impl Freeze for Doc

§

impl RefUnwindSafe for Doc

§

impl Send for Doc

§

impl Sync for Doc

§

impl Unpin for Doc

§

impl UnwindSafe for Doc

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more