generated from okp4/template-rust
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cognitarium): add atoms definition to help with rdf serde
- Loading branch information
Showing
3 changed files
with
40 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[derive(Eq, PartialEq, Debug, Clone, Hash)] | ||
pub enum Value { | ||
NamedNode(String), | ||
BlankNode(String), | ||
LiteralSimple(String), | ||
LiteralLang(String, String), | ||
LiteralDatatype(String, String), | ||
} | ||
|
||
use std::fmt; | ||
impl fmt::Display for Value { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Value::NamedNode(s) => write!(f, "{}", s), | ||
Value::BlankNode(s) => write!(f, "{}", s), | ||
Value::LiteralSimple(s) => write!(f, "{}", s), | ||
Value::LiteralLang(s, l) => write!(f, "{}@{}", s, l), | ||
Value::LiteralDatatype(s, d) => write!(f, "{}^^{}", s, d), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Eq, PartialEq, Debug, Clone, Hash)] | ||
pub struct Atom { | ||
pub subject: String, | ||
pub property: String, | ||
pub value: Value, | ||
} | ||
|
||
impl std::fmt::Display for Atom { | ||
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
fmt.write_str(&format!( | ||
"<{}> <{}> '{}'", | ||
self.subject, self.property, self.value | ||
))?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod serde; | ||
mod uri; | ||
mod atom; | ||
|
||
pub use self::serde::*; | ||
pub use self::uri::*; | ||
pub use self::atom::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters