pub trait BuildRDF: NeighsRDF {
// Required methods
fn empty() -> Self;
fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>;
fn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>;
fn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>;
fn add_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
where S: Into<Self::Subject>,
P: Into<Self::IRI>,
O: Into<Self::Term>;
fn remove_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
where S: Into<Self::Subject>,
P: Into<Self::IRI>,
O: Into<Self::Term>;
fn add_type<S, T>(&mut self, node: S, type_: T) -> Result<(), Self::Err>
where S: Into<Self::Subject>,
T: Into<Self::Term>;
fn add_bnode(&mut self) -> Result<Self::BNode, Self::Err>;
fn serialize<W: Write>(
&self,
format: &RDFFormat,
writer: &mut W,
) -> Result<(), Self::Err>;
}Expand description
Trait for building and modifying RDF graphs.
This trait provides methods for constructing RDF graphs by adding triples,
managing namespace prefixes, creating blank nodes, and serializing the
graph to various RDF formats. It extends NeighsRDF with mutation
capabilities.
Required Methods§
Sourcefn empty() -> Self
fn empty() -> Self
Creates a new empty RDF graph.
Returns a graph with no triples, no prefix declarations, and no base IRI. This is the starting point for building RDF data.
Sourcefn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>
fn add_base(&mut self, base: &Option<IriS>) -> Result<(), Self::Err>
Sets the base IRI for resolving relative IRI references.
§Arguments
base- Optional base IRI for resolving relative references
Sourcefn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>
fn add_prefix(&mut self, alias: &str, iri: &IriS) -> Result<(), Self::Err>
Adds a namespace prefix declaration to the graph.
§Arguments
alias- The prefix alias (e.g., “foaf”, “ex”, “rdf”)iri- The full namespace IRI this prefix represents
Sourcefn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>
fn add_prefix_map(&mut self, prefix_map: PrefixMap) -> Result<(), Self::Err>
Adds multiple prefix declarations from a prefix map.
§Arguments
prefix_map- A map of prefix aliases to namespace IRIs
Sourcefn add_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
fn add_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
Adds an RDF triple to the graph.
§Type Parameters
S- Type convertible to the subject representationP- Type convertible to the predicate (IRI) representationO- Type convertible to the object (term) representation
§Arguments
subj- The subject of the triple (IRI or blank node)pred- The predicate of the triple (must be an IRI)obj- The object of the triple (IRI, blank node, or literal)
Sourcefn remove_triple<S, P, O>(
&mut self,
subj: S,
pred: P,
obj: O,
) -> Result<(), Self::Err>
fn remove_triple<S, P, O>( &mut self, subj: S, pred: P, obj: O, ) -> Result<(), Self::Err>
Removes an RDF triple from the graph.
§Type Parameters
S- Type convertible to the subject representationP- Type convertible to the predicate (IRI) representationO- Type convertible to the object (term) representation
§Arguments
subj- The subject of the triple to removepred- The predicate of the triple to removeobj- The object of the triple to remove
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl BuildRDF for InMemoryGraph
Implementation of the BuildRDF trait for constructing and modifying RDF graphs.
This implementation provides methods to build RDF graphs programmatically by adding prefixes, base IRIs, blank nodes, triples, and types. It also supports serialization to various RDF formats.