Skip to main content

Node

Struct 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<Graph<T, B>>,
    pub included: Option<Included<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 include other 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<Graph<T, B>>

Associated graph.

This is the @graph field.

§included: Option<Included<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() -> Self

Creates a new empty node.

Source

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

Creates a new empty node with the given id.

Source

pub fn new_graph(id: Id<T, B>, graph: Graph<T, B>) -> Self

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 Included<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: VocabularyMut<Iri = T, BlankId = B>, G: LocalGenerator>( &mut self, vocabulary: &mut V, generator: &mut G, ) -> Result<(), GeneratedIdError>
where T: Eq + Hash, B: Eq + Hash,

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

§Errors

Returns an error when the generator runs out of identifiers.

Source

pub fn identify_all<G: LocalGenerator>( &mut self, generator: &mut G, ) -> Result<(), GeneratedIdError>
where 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.

§Errors

Returns an error when the generator runs out of identifiers.

Source

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

Puts every literal of the node into canonical form, using the given buffer to render numbers.

Source

pub fn canonicalize(&mut self)

Puts every literal of the node into canonical form.

Source

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

Returns the node’s identifier as an IRI, if the node has one and it is an IRI.

Source

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

Returns the node’s identifier as a string slice.

Returns None if the node has no @id field.

Source

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

Returns the types of the node, or an empty slice if it has no @type entry.

Source

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

Mutably borrows the types of the node, or an empty slice if it has no @type entry.

Source

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

Mutably borrows the types of this node, inserting an empty list if it has none.

Source

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

Mutably borrows the types of this node, inserting value if it has none.

Source

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

Mutably borrows the types of this node, inserting the result of f if it has none.

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 if 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). A node object with a @graph entry is not considered a graph object if it includes any entry 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<&Graph<T, B>>

Returns the node objects of the @graph entry, if the node has one.

Note that having a @graph entry is necessary but not sufficient for the node to be a graph object; see is_graph.

Source

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

Mutably borrows the node objects of the @graph entry, if the node has one.

Source

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

Returns the node objects of the @graph entry, if the node has one.

Alias for graph.

Source

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

Mutably borrows the node objects of the @graph entry, if the node has one.

Alias for graph_mut.

Source

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

Sets the @graph entry of the node, or removes it when given None.

Source

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

Returns the set of nodes included by this node.

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

Source

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

Returns the mutable set of nodes included by this node.

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

Source

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

Returns a reference to the set of @included nodes.

Source

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

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

Source

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

Sets the @included entry of the node, or removes it when given None.

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 reverse properties of the node, if it has a @reverse entry.

Source

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

Returns a reference to the reverse properties of the node, if it has a @reverse entry.

Source

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

Returns a mutable reference to the reverse properties of the node, if it has a @reverse entry.

Source

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

Sets the reverse properties of this Node.

Source

pub fn is_unnamed_graph(&self) -> bool

Tests if the node is an unnamed graph object.

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

Source

pub fn into_unnamed_graph(self: Box<Self>) -> Result<Graph<T, B>, Box<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.

§Errors

Returns self unchanged when the object is not a graph object, or is a named graph.

Source

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

Returns an iterator that visits every fragment of the node: the node itself and, recursively, everything it contains.

Source

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

Counts the fragments of the node matching the given predicate.

Source

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

Returns an iterator over the entries of the JSON representation of the node.

Source

pub fn map_ids<U, C>( self, map_iri: impl FnMut(T) -> U, map_id: impl FnMut(Id<T, B>) -> Id<U, C>, ) -> Node<U, C>
where U: Eq + Hash, C: Eq + Hash,

Rewrites every IRI and identifier of the node (recursively) with the given functions.

Source§

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

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> ⓘ
where T: 'a,

Returns all the objects associated with the node through the given property.

Source

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

Returns one of the objects associated with the node through the given property.

If multiple objects are attached to the node with this property, there is no guarantee on which object is returned.

Source

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

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

Source

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

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

If objects are already associated with the property, the new ones are appended to them. Duplicate objects are not removed.

Source

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

Mutably borrows the reverse properties, inserting props if there are none.

Source

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

Mutably borrows the reverse properties, inserting an empty set if there are none.

Source

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

Mutably borrows the reverse properties, inserting the result of f if there are none.

Source

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

Equivalence operator.

Equivalence differs from equality for anonymous objects: an anonymous node object stands for an implicit, unlabeled blank node, so it is never equivalent to anything.

Trait Implementations§

Source§

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

Source§

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

Borrows the object as a value, node or list reference.
Source§

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

Returns the identifier (@id) of the object, if it is a node object with one.
Source§

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

Returns the language tag of this value, if it carries one.
Source§

fn is_value(&self) -> bool

Checks whether the object is a value object.
Source§

fn is_node(&self) -> bool

Checks whether the object is a node object.
Source§

fn is_graph(&self) -> bool

Checks whether the object is a graph object (a node object with a @graph entry).
Source§

fn is_list(&self) -> bool

Checks whether the object is a list object.
Source§

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

Source§

fn clone(&self) -> Self

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

Source§

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

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

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

Source§

fn default() -> Self

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

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

Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

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

Source§

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

Converts this value into JSON, resolving the identifiers it holds against the given vocabulary. Read more
Source§

impl<T, B, I: Interpretation> LinkedData<I> for Node<T, B>

Source§

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

Visit the RDF dataset represented by this type.
Source§

impl<T, B, I: Interpretation> LinkedDataGraph<I> for Node<T, B>

Source§

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

Visits the subjects of the graph represented by this value.
Source§

impl<T, B, I: Interpretation> LinkedDataPredicateObjects<I> for Node<T, B>

Source§

fn visit_objects<S>(&self, visitor: S) -> Result<S::Ok, S::Error>

Visits the objects this predicate points at.
Source§

impl<T, B, I: Interpretation> LinkedDataResource<I> for Node<T, B>

Source§

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

Returns the interpretation of this resource, inserting it into interpretation if required.
Source§

fn lexical_representation<'a>( &'a self, interpretation: &'a mut I, ) -> Option<CowRdfTerm<'a>>

Returns the lexical term representing this resource, if any.
Source§

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

Returns the interpretation to use when this resource appears as a reference rather than as a subject with properties.
Source§

impl<T, B, I: Interpretation> LinkedDataSubject<I> for Node<T, B>

Source§

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

Visits the properties of the subject represented by this value.
Source§

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

Source§

type BlankId = B

Blank node identifier type the renaming applies to.
Source§

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

Structural equality with mapped blank identifiers. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Computes the printed size of this value against context.
Source§

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

Source§

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

Writes the value to f, resolving it against context. Read more
Source§

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

Source§

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

Writes the value to f against context, taking its layout from sizes[*index]. Read more
Source§

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

Source§

fn relabel_with<N: VocabularyMut<Iri = T, BlankId = B>, G: LocalGenerator>( &mut self, vocabulary: &mut N, generator: &mut G, relabeling: &mut HashMap<B, ValidId<T, B>>, ) -> Result<(), GeneratedIdError>
where T: Clone + Eq + Hash, B: Clone + Eq + Hash,

Relabels every blank node, recording the mapping so shared nodes keep the same new identifier. Read more
Source§

fn relabel<G: LocalGenerator>( &mut self, generator: &mut G, relabeling: &mut HashMap<B, ValidId<T, B>>, ) -> Result<(), GeneratedIdError>
where T: Clone + Eq + Hash, B: Clone + Eq + Hash, (): Vocabulary<Iri = T, BlankId = B>,

Relabels every blank node, recording the mapping. Read more
Source§

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

Source§

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: Eq + Hash, B: Eq + Hash> TryFromJsonObject<T, B> for Node<T, B>

Source§

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

Builds this fragment from a JSON object, interning terms in the given vocabulary. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<T, B> Send for Node<T, B>
where Option<Id<T, B>>: Send, Option<Vec<Id<T, B>>>: Send, Option<Vec<Indexed<Object<T, B>>>>: Send, Option<Vec<Indexed<Node<T, B>>>>: Send, Properties<T, B>: Send, Option<ReverseProperties<T, B>>: Send,

§

impl<T, B> Sync for Node<T, B>
where Option<Id<T, B>>: Sync, Option<Vec<Id<T, B>>>: Sync, Option<Vec<Indexed<Object<T, B>>>>: Sync, Option<Vec<Indexed<Node<T, B>>>>: Sync, Properties<T, B>: Sync, Option<ReverseProperties<T, B>>: Sync,

§

impl<T, B> Unpin for Node<T, B>
where Option<Id<T, B>>: Unpin, Option<Vec<Id<T, B>>>: Unpin, Option<Vec<Indexed<Object<T, B>>>>: Unpin, Option<Vec<Indexed<Node<T, B>>>>: Unpin, Properties<T, B>: Unpin, Option<ReverseProperties<T, B>>: Unpin,

§

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

§

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

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

Source§

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

Views this value as an Unordered reference.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

Source§

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

Checks if self is equivalent to key.
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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

Source§

type Error = !

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

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

impl<T, U, C> TryIntoWithContext<U, C> for T
where U: TryFromWithContext<T, C>,

Source§

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>
where T: Sized,

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