Struct json_ld::Node

source ·
pub struct Node<T = IriBuf, B = BlankIdBuf> {
    pub id: Option<Id<T, B>>,
    pub types: Option<Vec<Id<T, B>>>,
    pub graph: Option<IndexSet<Indexed<Object<T, B>>>>,
    pub included: Option<IndexSet<Indexed<Node<T, B>>>>,
    pub properties: Properties<T, B>,
    pub reverse_properties: Option<ReverseProperties<T, B>>,
}
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).

Fields§

§id: Option<Id<T, B>>

Identifier.

This is the @id field.

§types: Option<Vec<Id<T, B>>>

Types.

This is the @type field.

§graph: Option<IndexSet<Indexed<Object<T, B>>>>

Associated graph.

This is the @graph field.

§included: Option<IndexSet<Indexed<Node<T, B>>>>

Included nodes.

This is the @included field.

§properties: Properties<T, B>

Properties.

Any non-keyword field.

§reverse_properties: Option<ReverseProperties<T, B>>

Reverse properties.

This is the @reverse field.

Implementations§

source§

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

source

pub fn new() -> Node<T, B>

Creates a new empty node.

source

pub fn with_id(id: Id<T, B>) -> Node<T, B>

Creates a new empty node with the given id.

source

pub fn new_graph( id: Id<T, B>, graph: IndexSet<Indexed<Object<T, B>>> ) -> Node<T, B>

Creates a new graph node.

source

pub fn reverse_properties_mut_or_default( &mut self ) -> &mut ReverseProperties<T, B>

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

If no @reverse entry is present, one is created.

source

pub fn included_mut_or_default(&mut self) -> &mut IndexSet<Indexed<Node<T, B>>>

Returns a mutable reference to the included nodes.

If no @included entry is present, one is created.

source

pub fn identify_all_with<V, G>(&mut self, vocabulary: &mut V, generator: &mut G)
where V: Vocabulary<Iri = T, BlankId = B>, G: Generator<V>, 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>(&mut self, generator: &mut G)
where G: Generator, 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) -> &[Id<T, B>]

Get the list of the node’s types.

source

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

Returns a mutable reference to the node’s types.

source

pub fn types_mut_or_default(&mut self) -> &mut Vec<Id<T, B>>

source

pub fn types_mut_or_insert( &mut self, value: Vec<Id<T, B>> ) -> &mut Vec<Id<T, B>>

source

pub fn types_mut_or_insert_with( &mut self, f: impl FnOnce() -> Vec<Id<T, B>> ) -> &mut Vec<Id<T, B>>

source

pub fn has_type<U>(&self, ty: &U) -> bool
where 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<&IndexSet<Indexed<Object<T, B>>>>

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

source

pub fn graph_mut(&mut self) -> Option<&mut IndexSet<Indexed<Object<T, B>>>>

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

source

pub fn graph_entry(&self) -> Option<&IndexSet<Indexed<Object<T, B>>>>

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

source

pub fn graph_entry_mut( &mut self ) -> Option<&mut IndexSet<Indexed<Object<T, B>>>>

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

source

pub fn set_graph_entry( &mut self, graph: Option<IndexSet<Indexed<Object<T, B>>>> )

Set the graph.

source

pub fn included_entry(&self) -> Option<&IndexSet<Indexed<Node<T, B>>>>

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 IndexSet<Indexed<Node<T, B>>>>

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<&IndexSet<Indexed<Node<T, B>>>>

Returns a reference to the set of @included nodes.

source

pub fn included_mut(&mut self) -> Option<&mut IndexSet<Indexed<Node<T, B>>>>

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

source

pub fn set_included(&mut self, included: Option<IndexSet<Indexed<Node<T, B>>>>)

Set the set of nodes included by the node.

source

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

Returns a reference to the properties of the node.

source

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

Returns a mutable reference to the properties of the node.

source

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

Returns a reference to the properties of the node.

source

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

Returns a reference to the reverse properties of the node.

source

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

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

source

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

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<IndexSet<Indexed<Object<T, B>>>, Node<T, B>>

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>

source

pub fn count(&self, f: impl FnMut(&FragmentRef<'_, T, B>) -> bool) -> usize

source

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

source§

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

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>(&self, prop: &Q) -> Objects<'_, T, B>
where Q: Hash + Equivalent<Id<T, B>> + ?Sized, T: 'a,

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

source

pub fn get_any<'a, Q>(&self, prop: &Q) -> Option<&Indexed<Object<T, B>>>
where Q: Hash + Equivalent<Id<T, B>> + ?Sized, 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: Id<T, B>, value: Indexed<Object<T, B>>)

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

source

pub fn insert_all<Objects>(&mut self, prop: Id<T, B>, values: Objects)
where Objects: Iterator<Item = Indexed<Object<T, B>>>,

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, props: ReverseProperties<T, B> ) -> &mut ReverseProperties<T, B>

source

pub fn reverse_properties_or_default(&mut self) -> &mut ReverseProperties<T, B>

source

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

source

pub fn equivalent(&self, other: &Node<T, B>) -> 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> Any<T, B> for Node<T, B>

source§

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

source§

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

source§

fn language<'a>(&'a self) -> Option<&'a LenientLangTag>
where T: 'a, B: '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, B> Clone for Node<T, B>
where T: Clone, B: Clone,

source§

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

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> Debug for Node<T, B>
where T: Debug, B: Debug,

source§

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

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

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

source§

fn default() -> Node<T, B>

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

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

source§

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

Converts to this type from the input type.
source§

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

source§

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

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, N> IntoJsonWithContext<N> for Node<T, B>
where N: Vocabulary<Iri = T, BlankId = B>,

source§

fn into_json_with(self, vocabulary: &N) -> Value

source§

impl<T, B, V, I> LinkedData<I, V> for Node<T, B>

source§

fn visit<S>( &self, visitor: S ) -> Result<<S as Visitor<I, V>>::Ok, <S as Visitor<I, V>>::Error>
where S: Visitor<I, V>,

Visit the RDF dataset represented by this type.
source§

impl<T, B, V, I> LinkedDataGraph<I, V> for Node<T, B>

source§

fn visit_graph<S>( &self, visitor: S ) -> Result<<S as GraphVisitor<I, V>>::Ok, <S as GraphVisitor<I, V>>::Error>
where S: GraphVisitor<I, V>,

source§

impl<T, B, V, I> LinkedDataPredicateObjects<I, V> for Node<T, B>

source§

fn visit_objects<S>( &self, visitor: S ) -> Result<<S as PredicateObjectsVisitor<I, V>>::Ok, <S as PredicateObjectsVisitor<I, V>>::Error>
where S: PredicateObjectsVisitor<I, V>,

source§

impl<T, B, V, I> LinkedDataResource<I, V> for Node<T, B>

source§

fn interpretation( &self, vocabulary: &mut V, interpretation: &mut I ) -> ResourceInterpretation<'_, I, V>

source§

fn reference_interpretation( &self, vocabulary: &mut V, interpretation: &mut I ) -> ResourceInterpretation<'_, I, V>

source§

impl<T, B, V, I> LinkedDataSubject<I, V> for Node<T, B>

source§

fn visit_subject<S>( &self, visitor: S ) -> Result<<S as SubjectVisitor<I, V>>::Ok, <S as SubjectVisitor<I, V>>::Error>
where S: SubjectVisitor<I, V>,

source§

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

§

type BlankId = B

source§

fn mapped_eq<'a, 'b, F>(&'a self, other: &Node<T, B>, f: F) -> bool
where F: Clone + Fn(&'a B) -> &'b B, B: 'a + 'b,

Structural equality with mapped blank identifiers. Read more
source§

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

source§

fn eq(&self, other: &Node<T, B>) -> 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, N> PrecomputeSizeWithContext<N> for Node<T, B>
where N: Vocabulary<Iri = T, BlankId = B>,

source§

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

source§

impl<T, B, N> PrintWithContext<N> for Node<T, B>
where N: Vocabulary<Iri = T, BlankId = B>,

source§

fn contextual_fmt_with( &self, vocabulary: &N, f: &mut Formatter<'_>, options: &Options, indent: usize ) -> Result<(), Error>

source§

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

source§

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

source§

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

source§

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

source§

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

§

type Error = Object<T, B>

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

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

Performs the conversion.
source§

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

source§

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

source§

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

Auto Trait Implementations§

§

impl<T, B> Freeze for Node<T, B>
where B: Freeze, T: Freeze,

§

impl<T, B> RefUnwindSafe for Node<T, B>

§

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

§

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

§

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

§

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

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

source§

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

source§

impl<T> BorrowUnordered for T

source§

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

source§

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

source§

impl<I, B, T> CompactIndexedFragment<I, B> for T
where T: Any<I, B>,

source§

async fn compact_indexed_fragment<'a, N, L>( &'a self, vocabulary: &'a mut N, index: Option<&'a str>, active_context: &'a Context<I, B>, type_scoped_context: &'a Context<I, B>, active_property: Option<&'a str>, loader: &'a mut L, options: Options ) -> Result<Value, Error<<L as Loader<I>>::Error>>
where N: VocabularyMut<Iri = I, BlankId = B>, I: Clone + Hash + Eq, B: Clone + Hash + Eq, L: Loader<I>,

source§

impl<Q, K> Equivalent<K> for Q
where 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 Q
where 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

source§

impl<Q, K> Equivalent<K> for Q
where 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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, C> FromWithContext<T, C> for T

source§

fn from_with(value: T, _context: &C) -> T

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, U, C> IntoWithContext<U, C> for T
where U: FromWithContext<T, C>,

source§

fn into_with(self, context: &C) -> U

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 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, C> TryFromWithContext<U, C> for T
where U: IntoWithContext<T, C>,

§

type Error = Infallible

source§

fn try_from_with( value: U, context: &C ) -> Result<T, <T as TryFromWithContext<U, C>>::Error>

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, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

§

type Error = <U as TryFromWithContext<T, C>>::Error

source§

fn try_into_with( self, context: &C ) -> Result<U, <T as TryIntoWithContext<U, C>>::Error>

source§

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

source§

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

source§

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

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