Struct json_ld_core::object::node::Node

source ·
pub struct Node<T = IriBuf, B = BlankIdBuf, M = ()> { /* private fields */ }
Expand description

Node object.

A node object represents zero or more properties of a node in the graph serialized by a JSON-LD document. A node is defined by its identifier (@id field), types, properties and reverse properties. In addition, a node may represent a graph (@graph field) and includes nodes (@included field).

Implementations§

source§

impl<T, B, M> Node<T, B, M>

source

pub fn new() -> Self

Creates a new empty node.

source

pub fn with_id(id: Entry<Id<T, B>, M>) -> Self

Creates a new empty node with the given id.

source

pub fn from_parts(parts: Parts<T, B, M>) -> Self

source

pub fn into_parts(self) -> Parts<T, B, M>

source

pub fn id(&self) -> Option<&Meta<Id<T, B>, M>>

Get the identifier of the node.

This correspond to the @id field of the JSON object.

source

pub fn id_entry(&self) -> Option<&Entry<Id<T, B>, M>>

Get the identifier of the node.

This correspond to the @id field of the JSON object.

source

pub fn set_id(&mut self, id: Option<Entry<Id<T, B>, M>>)

Sets the idntifier of this node.

source

pub fn identify_all_with<V: Vocabulary<Iri = T, BlankId = B>, G: Generator<V, M>>( &mut self, vocabulary: &mut V, generator: &mut G )where M: Clone, T: Eq + Hash, B: Eq + Hash,

Assigns an identifier to this node and every other node included in this one using the given generator.

source

pub fn identify_all<G: Generator<(), M>>(&mut self, generator: &mut G)where M: Clone, T: Eq + Hash, B: Eq + Hash, (): Vocabulary<Iri = T, BlankId = B>,

Assigns an identifier to this node and every other node included in this one using the given generator.

source

pub fn canonicalize_with(&mut self, buffer: &mut Buffer)

Puts this node object literals into canonical form using the given buffer.

The buffer is used to compute the canonical form of numbers.

source

pub fn canonicalize(&mut self)

Puts this node object literals into canonical form.

source

pub fn as_iri(&self) -> Option<&T>

Get the node’s as an IRI if possible.

Returns the node’s IRI id if any. Returns None otherwise.

source

pub fn as_str(&self) -> Option<&str>where T: AsRef<str>,

Get the node’s id, is any, as a string slice.

Returns None if the node has no @id field.

source

pub fn types(&self) -> &[Meta<Id<T, B>, M>]

Get the list of the node’s types.

source

pub fn types_mut(&mut self) -> &mut [Meta<Id<T, B>, M>]

Returns a mutable reference to the node’s types.

source

pub fn type_entry_or_default( &mut self, key_metadata: M, value_metadata: M ) -> &mut TypeEntry<T, B, M>

source

pub fn type_entry_or_insert( &mut self, key_metadata: M, value: TypeEntryValue<T, B, M> ) -> &mut TypeEntry<T, B, M>

source

pub fn type_entry_or_insert_with( &mut self, f: impl FnOnce() -> TypeEntry<T, B, M> ) -> &mut TypeEntry<T, B, M>

source

pub fn type_entry(&self) -> Option<&TypeEntry<T, B, M>>

source

pub fn set_type_entry(&mut self, entry: Option<TypeEntry<T, B, M>>)

source

pub fn has_type<U>(&self, ty: &U) -> boolwhere Id<T, B>: PartialEq<U>,

Checks if the node has the given type.

source

pub fn is_empty(&self) -> bool

Tests if the node is empty.

It is empty is every field other than @id is empty.

source

pub fn is_graph(&self) -> bool

Tests if the node is a graph object (has a @graph field, and optionally an @id field). Note that node objects may have a @graph entry, but are not considered graph objects if they include any other entries other than @id.

source

pub fn is_simple_graph(&self) -> bool

Tests if the node is a simple graph object (a graph object without @id field)

source

pub fn graph(&self) -> Option<&Meta<Graph<T, B, M>, M>>

If the node is a graph object, get the graph.

source

pub fn graph_mut(&mut self) -> Option<&mut Meta<Graph<T, B, M>, M>>

If the node is a graph object, get the mutable graph.

source

pub fn graph_entry(&self) -> Option<&GraphEntry<T, B, M>>

If the node is a graph object, get the graph.

source

pub fn graph_entry_mut(&mut self) -> Option<&mut GraphEntry<T, B, M>>

If the node is a graph object, get the mutable graph.

source

pub fn set_graph(&mut self, graph: Option<GraphEntry<T, B, M>>)

Set the graph.

source

pub fn included_entry(&self) -> Option<&IncludedEntry<T, B, M>>

Get the set of nodes included by this node.

This correspond to the @included field in the JSON representation.

source

pub fn included_entry_mut(&mut self) -> Option<&mut IncludedEntry<T, B, M>>

Get the mutable set of nodes included by this node.

This correspond to the @included field in the JSON representation.

source

pub fn included(&self) -> Option<&Meta<Included<T, B, M>, M>>

Returns a reference to the set of @included nodes.

source

pub fn included_mut(&mut self) -> Option<&mut Meta<Included<T, B, M>, M>>

Returns a mutable reference to the set of @included nodes.

source

pub fn set_included(&mut self, included: Option<IncludedEntry<T, B, M>>)

Set the set of nodes included by the node.

source

pub fn properties(&self) -> &Properties<T, B, M>

Returns a reference to the properties of the node.

source

pub fn properties_mut(&mut self) -> &mut Properties<T, B, M>

Returns a mutable reference to the properties of the node.

source

pub fn reverse_properties(&self) -> Option<&Meta<ReverseProperties<T, B, M>, M>>

Returns a reference to the properties of the node.

source

pub fn reverse_properties_entry( &self ) -> Option<&Entry<ReverseProperties<T, B, M>, M>>

Returns a reference to the reverse properties of the node.

source

pub fn reverse_properties_mut( &mut self ) -> Option<&mut Entry<ReverseProperties<T, B, M>, M>>

Returns a mutable reference to the reverse properties of the node.

source

pub fn set_reverse_properties( &mut self, reverse_properties: Option<Entry<ReverseProperties<T, B, M>, M>> )

source

pub fn is_unnamed_graph(&self) -> bool

Tests if the node is an unnamed graph object.

Returns true is the only field of the object is a @graph field. Returns false otherwise.

source

pub fn into_unnamed_graph(self) -> Result<Entry<Graph<T, B, M>, M>, Self>

Returns the node as an unnamed graph, if it is one.

The unnamed graph is returned as a set of indexed objects. Fails and returns itself if the node is not an unnamed graph.

source

pub fn traverse(&self) -> Traverse<'_, T, B, M>

source

pub fn entries(&self) -> Entries<'_, T, B, M>

source§

impl<T: Eq + Hash, B: Eq + Hash, M> Node<T, B, M>

source

pub fn has_key(&self, key: &Term<T, B>) -> bool

Checks if the node object has the given term as key.

Example

// Checks if the JSON object representation of the node has an `@id` key.
if node.has_key(&Term::Keyword(Keyword::Id)) {
  // ...
}
source

pub fn get<'a, Q: ?Sized + Hash + Equivalent<Id<T, B>>>( &self, prop: &Q ) -> Objects<'_, T, B, M> where T: 'a,

Get all the objects associated to the node with the given property.

source

pub fn get_any<'a, Q: ?Sized + Hash + Equivalent<Id<T, B>>>( &self, prop: &Q ) -> Option<&IndexedObject<T, B, M>>where T: 'a,

Get one of the objects associated to the node with the given property.

If multiple objects are attached to the node with this property, there are no guaranties on which object will be returned.

source

pub fn insert(&mut self, prop: Meta<Id<T, B>, M>, value: IndexedObject<T, B, M>)

Associates the given object to the node through the given property.

source

pub fn insert_all<Objects: Iterator<Item = IndexedObject<T, B, M>>>( &mut self, prop: Meta<Id<T, B>, M>, values: Objects )

Associates all the given objects to the node through the given property.

If there already exists objects associated to the given reverse property, reverse_value is added to the list. Duplicate objects are not removed.

source

pub fn reverse_properties_or_insert( &mut self, key_metadata: M, props: Meta<ReverseProperties<T, B, M>, M> ) -> &mut Entry<ReverseProperties<T, B, M>, M>

source

pub fn reverse_properties_or_default( &mut self, key_metadata: M, value_metadata: M ) -> &mut Entry<ReverseProperties<T, B, M>, M>

source

pub fn reverse_properties_or_insert_with( &mut self, f: impl FnOnce() -> Entry<ReverseProperties<T, B, M>, M> ) -> &mut Entry<ReverseProperties<T, B, M>, M>

source

pub fn equivalent(&self, other: &Self) -> bool

Equivalence operator.

Equivalence is different from equality for anonymous objects. Anonymous node objects have an implicit unlabeled blank nodes and thus never equivalent.

Trait Implementations§

source§

impl<T, B, M> Any<T, B, M> for Node<T, B, M>

source§

fn as_ref(&self) -> Ref<'_, T, B, M>

source§

fn id_entry<'a>(&'a self) -> Option<&'a Entry<Id<T, B>, M>>where M: 'a,

source§

fn id<'a>(&'a self) -> Option<&'a Meta<Id<T, B>, M>>where M: 'a,

source§

fn language<'a>(&'a self) -> Option<LenientLanguageTag<'_>>where T: 'a, B: 'a, M: 'a,

source§

fn is_value(&self) -> bool

source§

fn is_node(&self) -> bool

source§

fn is_graph(&self) -> bool

source§

fn is_list(&self) -> bool

source§

impl<T: Clone, B: Clone, M: Clone> Clone for Node<T, B, M>

source§

fn clone(&self) -> Node<T, B, M>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, B, M> Default for Node<T, B, M>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T, B, M> From<Node<T, B, M>> for Object<T, B, M>

source§

fn from(node: Node<T, B, M>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash, B: Hash, M: Hash> Hash for Node<T, B, M>

source§

fn hash<H: Hasher>(&self, h: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T, B, M: Clone, N: Vocabulary<Iri = T, BlankId = B>> IntoJsonWithContextMeta<M, N> for Node<T, B, M>

source§

fn into_json_meta_with(self, meta: M, vocabulary: &N) -> Meta<Value<M>, M>

source§

impl<T: Eq + Hash, B: Eq + Hash, M> MappedEq<Node<T, B, M>> for Node<T, B, M>

§

type BlankId = B

source§

fn mapped_eq<'a, 'b, F: Clone + Fn(&'a B) -> &'b B>( &'a self, other: &Self, f: F ) -> boolwhere B: 'a + 'b,

Structural equality with mapped blank identifiers. Read more
source§

impl<T: Eq + Hash, B: Eq + Hash, M: PartialEq> PartialEq<Node<T, B, M>> for Node<T, B, M>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T, B, M, N: Vocabulary<Iri = T, BlankId = B>> PrecomputeSizeWithContext<N> for Node<T, B, M>

source§

fn contextual_pre_compute_size( &self, vocabulary: &N, options: &Options, sizes: &mut Vec<Size> ) -> Size

source§

impl<T, B, M, N: Vocabulary<Iri = T, BlankId = B>> PrintWithSizeAndContext<N> for Node<T, B, M>

source§

fn contextual_fmt_with_size( &self, vocabulary: &N, f: &mut Formatter<'_>, options: &Options, indent: usize, sizes: &[Size], index: &mut usize ) -> Result

source§

impl<T, B, M> Relabel<T, B, M> for Node<T, B, M>

source§

fn relabel_with<N: Vocabulary<Iri = T, BlankId = B>, G: MetaGenerator<N, M>>( &mut self, vocabulary: &mut N, generator: &mut G, relabeling: &mut HashMap<B, Meta<Subject<T, B>, M>> )where M: Clone, T: Clone + Eq + Hash, B: Clone + Eq + Hash,

source§

impl<T: Hash, B: Hash, M> StrippedHash for Node<T, B, M>

source§

impl<T: Eq + Hash, B: Eq + Hash, M> StrippedPartialEq<Node<T, B, M>> for Node<T, B, M>

source§

fn stripped_eq(&self, other: &Self) -> bool

source§

impl<T, B, M> TryFrom<Object<T, B, M>> for Node<T, B, M>

§

type Error = Object<T, B, M>

The type returned in the event of a conversion error.
source§

fn try_from(obj: Object<T, B, M>) -> Result<Node<T, B, M>, Object<T, B, M>>

Performs the conversion.
source§

impl<T: Eq + Hash, B: Eq + Hash, M> TryFromJsonObject<T, B, M> for Node<T, B, M>

source§

fn try_from_json_object_in( vocabulary: &mut impl VocabularyMut<Iri = T, BlankId = B>, object: Meta<Object<M>, M> ) -> Result<Meta<Self, M>, Meta<InvalidExpandedJson<M>, M>>

source§

impl<T, B, M> Eq for Node<T, B, M>where T: Eq + Hash, B: Eq + Hash, M: Eq,

source§

impl<T: Eq + Hash, B: Eq + Hash, M> StrippedEq for Node<T, B, M>

Auto Trait Implementations§

§

impl<T, B, M> RefUnwindSafe for Node<T, B, M>where B: RefUnwindSafe, M: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, B, M> Send for Node<T, B, M>where B: Send, M: Send, T: Send,

§

impl<T, B, M> Sync for Node<T, B, M>where B: Sync, M: Sync, T: Sync,

§

impl<T, B, M> Unpin for Node<T, B, M>where B: Unpin, M: Unpin, T: Unpin,

§

impl<T, B, M> UnwindSafe for Node<T, B, M>where B: UnwindSafe, M: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> At for T

source§

fn at<M>(self, metadata: M) -> Meta<T, M>

Wraps self inside a Meta<Self, M> using the given metadata. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> BorrowStripped for T

source§

fn stripped(&self) -> &Stripped<T>

source§

impl<T> BorrowUnordered for T

source§

fn unordered(&self) -> &Unordered<T>

§

impl<T> CallHasher for Twhere T: Hash + ?Sized,

§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64where H: Hash + ?Sized, B: BuildHasher,

source§

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

source§

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

source§

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

source§

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

Checks if this value is equivalent to the given key. Read more
source§

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

source§

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

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere T: Clone,

§

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

§

type Owned = T

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithContext for Twhere T: ?Sized,

source§

fn with<C>(&self, context: C) -> Contextual<&T, C>

source§

fn into_with<C>(self, context: C) -> Contextual<T, C>