Fork of https://github.com/oxigraph/oxigraph.git for the purpose of NextGraph project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.2 KiB
44 lines
1.2 KiB
7 years ago
|
use std::fmt;
|
||
|
use uuid::Uuid;
|
||
|
|
||
6 years ago
|
/// A RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node).
|
||
|
///
|
||
|
/// This implementation enforces that the blank node id is an UUID to easily ensure
|
||
|
/// that it is not possible for two blank nodes to share an id.
|
||
|
///
|
||
|
/// The common way to create a new blank node is to use the `Default::default` trait method.
|
||
|
///
|
||
|
/// The default string formatter is returning a N-Triples, Turtle and SPARQL compatible representation.
|
||
|
/// `BlankNode::default().to_string()` should return something like `_:00112233445566778899aabbccddeeff`
|
||
|
///
|
||
7 years ago
|
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
|
||
|
pub struct BlankNode {
|
||
|
id: Uuid,
|
||
|
}
|
||
|
|
||
6 years ago
|
impl BlankNode {
|
||
|
/// Returns the underlying UUID of this blank node
|
||
|
pub fn as_uuid(&self) -> &Uuid {
|
||
7 years ago
|
&self.id
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl fmt::Display for BlankNode {
|
||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||
6 years ago
|
write!(f, "_:{}", self.id.to_simple())
|
||
7 years ago
|
}
|
||
|
}
|
||
|
|
||
|
impl Default for BlankNode {
|
||
|
/// Builds a new RDF [blank node](https://www.w3.org/TR/rdf11-concepts/#dfn-blank-node) with a unique id
|
||
|
fn default() -> Self {
|
||
|
BlankNode { id: Uuid::new_v4() }
|
||
|
}
|
||
|
}
|
||
7 years ago
|
|
||
|
impl From<Uuid> for BlankNode {
|
||
|
fn from(id: Uuid) -> Self {
|
||
|
Self { id }
|
||
|
}
|
||
|
}
|