astreams
: get to something reasonable??
This commit is contained in:
parent
60af998994
commit
0c5dc9e5ca
4 changed files with 170 additions and 151 deletions
|
@ -21,6 +21,8 @@ thiserror = "2.0.3"
|
|||
mediatype = { version = "0.19.18", features = ["serde"] }
|
||||
chrono = { version = "0.4.39", features = ["serde"] }
|
||||
speedate = "0.15.0"
|
||||
indexmap = "2.6.0"
|
||||
tokio = { version = "1.41.1", features = ["net"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.41.1", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
@ -13,12 +13,19 @@ use mediatype::MediaType;
|
|||
use super::{LangDir, LangString, HasLinkedDataInterface, ResultGetMany, ResultGetOne, ResultSetMany, ResultSetOne};
|
||||
|
||||
impl HasLinkedDataInterface for Node {
|
||||
fn ld_has_type(&self, id: &Id) -> bool {
|
||||
self.has_type(id)
|
||||
fn ld_has_type(&self, id: &str) -> bool
|
||||
{
|
||||
self.has_type(
|
||||
&Id::from_string(
|
||||
id.to_string()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fn ld_get_string(&self, id: &Id) -> ResultGetOne<String> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_string(&self, id: &str) -> ResultGetOne<String> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -35,8 +42,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(string))
|
||||
}
|
||||
|
||||
fn ld_get_string_id(&self, id: &Id) -> ResultGetOne<String> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_string_id(&self, id: &str) -> ResultGetOne<String> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let node = match property.as_node() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD node"))),
|
||||
|
@ -53,8 +62,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(string))
|
||||
}
|
||||
|
||||
fn ld_get_mediatype(&self, id: &Id) -> ResultGetOne<MediaType> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_mediatype(&self, id: &str) -> ResultGetOne<MediaType> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -74,8 +85,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(mediatype))
|
||||
}
|
||||
|
||||
fn ld_get_langtag(&self, id: &Id) -> ResultGetOne<LangTagBuf> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_langtag(&self, id: &str) -> ResultGetOne<LangTagBuf> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -97,8 +110,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(langtag))
|
||||
}
|
||||
|
||||
fn ld_get_u32(&self, id: &Id) -> ResultGetOne<u32> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_u32(&self, id: &str) -> ResultGetOne<u32> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -118,8 +133,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(r#u32))
|
||||
}
|
||||
|
||||
fn ld_get_u64(&self, id: &Id) -> ResultGetOne<u64> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_u64(&self, id: &str) -> ResultGetOne<u64> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -139,8 +156,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(r#u64))
|
||||
}
|
||||
|
||||
fn ld_get_timedelta(&self, id: &Id) -> ResultGetOne<TimeDelta> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_timedelta(&self, id: &str) -> ResultGetOne<TimeDelta> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -168,8 +187,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(duration_chrono))
|
||||
}
|
||||
|
||||
fn ld_get_datetime_local(&self, id: &Id) -> ResultGetOne<DateTime<Local>> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_datetime_local(&self, id: &str) -> ResultGetOne<DateTime<Local>> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let value = match property.as_value() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD value"))),
|
||||
|
@ -191,8 +212,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(datetime_local))
|
||||
}
|
||||
|
||||
fn ld_get_strings(&self, id: &Id) -> ResultGetMany<String> {
|
||||
let properties = self.properties.get(id);
|
||||
fn ld_get_strings(&self, id: &str) -> ResultGetMany<String> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let properties = self.properties.get(&id);
|
||||
|
||||
let values = properties.map(|v| v
|
||||
.as_value()
|
||||
|
@ -215,8 +238,10 @@ impl HasLinkedDataInterface for Node {
|
|||
strings.collect()
|
||||
}
|
||||
|
||||
fn ld_get_langstrings(&self, id: &Id) -> ResultGetMany<LangString> {
|
||||
let properties = self.properties.get(id);
|
||||
fn ld_get_langstrings(&self, id: &str) -> ResultGetMany<LangString> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let properties = self.properties.get(&id);
|
||||
|
||||
let values = properties.map(|v| v
|
||||
.as_value()
|
||||
|
@ -259,7 +284,9 @@ impl HasLinkedDataInterface for Node {
|
|||
values.collect()
|
||||
}
|
||||
|
||||
fn ld_set_string(&mut self, id: Id, value: String) -> ResultSetOne {
|
||||
fn ld_set_string(&mut self, id: &str, value: String) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let string = SynString::from(value);
|
||||
|
||||
let json = SynValue::String(string);
|
||||
|
@ -277,7 +304,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_string_id(&mut self, id: Id, value: String) -> ResultSetOne {
|
||||
fn ld_set_string_id(&mut self, id: &str, value: String) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let value_iri = IriBuf::new(value)
|
||||
.context("Couldn't convert string into an IRI")?;
|
||||
|
||||
|
@ -301,7 +330,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_mediatype(&mut self, id: Id, value: MediaType) -> ResultSetOne {
|
||||
fn ld_set_mediatype(&mut self, id: &str, value: MediaType) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let stringified = value.to_string();
|
||||
|
||||
let string = SynString::from(stringified);
|
||||
|
@ -321,7 +352,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_langtag(&mut self, id: Id, value: LangTagBuf) -> ResultSetOne {
|
||||
fn ld_set_langtag(&mut self, id: &str, value: LangTagBuf) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let stringified = value.as_str();
|
||||
|
||||
let string = SynString::from(stringified);
|
||||
|
@ -341,7 +374,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_u32(&mut self, id: Id, value: u32) -> ResultSetOne {
|
||||
fn ld_set_u32(&mut self, id: &str, value: u32) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let number = SynNumber::from(value);
|
||||
|
||||
let json = SynValue::Number(number);
|
||||
|
@ -359,7 +394,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_u64(&mut self, id: Id, value: u64) -> ResultSetOne {
|
||||
fn ld_set_u64(&mut self, id: &str, value: u64) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let number = SynNumber::from(value);
|
||||
|
||||
let json = SynValue::Number(number);
|
||||
|
@ -377,7 +414,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_timedelta(&mut self, id: Id, value: TimeDelta) -> ResultSetOne {
|
||||
fn ld_set_timedelta(&mut self, id: &str, value: TimeDelta) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let total_seconds = value.num_seconds();
|
||||
|
||||
if total_seconds.is_negative() {
|
||||
|
@ -403,7 +442,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_datetime_local(&mut self, id: Id, value: DateTime<Local>) -> ResultSetOne {
|
||||
fn ld_set_datetime_local(&mut self, id: &str, value: DateTime<Local>) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let stringified = value.to_rfc3339();
|
||||
|
||||
let string = SynString::from(stringified);
|
||||
|
@ -423,7 +464,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_strings(&mut self, id: Id, values: Vec<String>) -> ResultSetMany {
|
||||
fn ld_set_strings(&mut self, id: &str, values: Vec<String>) -> ResultSetMany {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let indexed_objects = values
|
||||
.into_iter()
|
||||
.map(|value| {
|
||||
|
@ -448,7 +491,9 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_set_langstrings(&mut self, id: Id, values: Vec<LangString>) -> ResultSetMany {
|
||||
fn ld_set_langstrings(&mut self, id: &str, values: Vec<LangString>) -> ResultSetMany {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let indexed_objects = values
|
||||
.into_iter()
|
||||
.map(|(string, langdir)| {
|
||||
|
@ -482,8 +527,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_get_child(&self, id: &Id) -> ResultGetOne<&Self> {
|
||||
let property = self.properties.get_any(id)?;
|
||||
fn ld_get_child(&self, id: &str) -> ResultGetOne<&Self> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let property = self.properties.get_any(&id)?;
|
||||
|
||||
let node = match property.as_node() {
|
||||
None => return Some(Err(anyhow!("Couldn't process property as JSON-LD node"))),
|
||||
|
@ -493,11 +540,13 @@ impl HasLinkedDataInterface for Node {
|
|||
Some(Ok(node))
|
||||
}
|
||||
|
||||
fn ld_into_child_mut(&mut self, id: &Id) -> ResultGetOne<&mut Self> {
|
||||
fn ld_into_child_mut(&mut self, id: &str) -> ResultGetOne<&mut Self> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
// TODO: Replace with a get_mut or similar when available
|
||||
let node = self.properties_mut()
|
||||
.iter_mut()
|
||||
.filter(|(cid, _)| cid == &id)
|
||||
.filter(|(cid, _)| *cid == &id)
|
||||
.flat_map(|(_, prop)| prop
|
||||
.iter_mut()
|
||||
.map(|obj| obj
|
||||
|
@ -510,7 +559,9 @@ impl HasLinkedDataInterface for Node {
|
|||
node
|
||||
}
|
||||
|
||||
fn ld_set_child(&mut self, id: Id, value: Self) -> ResultSetOne {
|
||||
fn ld_set_child(&mut self, id: &str, value: Self) -> ResultSetOne {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let boxed_node = Box::new(value);
|
||||
|
||||
let object: Object = Object::Node(boxed_node);
|
||||
|
@ -524,8 +575,10 @@ impl HasLinkedDataInterface for Node {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn ld_get_children(&self, id: &Id) -> ResultGetMany<&Self> {
|
||||
let properties = self.properties.get(id);
|
||||
fn ld_get_children(&self, id: &str) -> ResultGetMany<&Self> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let properties = self.properties.get(&id);
|
||||
|
||||
let nodes = properties.map(|v| v
|
||||
.as_node()
|
||||
|
@ -536,11 +589,13 @@ impl HasLinkedDataInterface for Node {
|
|||
nodes
|
||||
}
|
||||
|
||||
fn ld_into_children_mut(&mut self, id: &Id) -> ResultGetMany<&mut Self> {
|
||||
fn ld_into_children_mut(&mut self, id: &str) -> ResultGetMany<&mut Self> {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
// TODO: Replace with a get_mut or similar when available
|
||||
let nodes = self.properties_mut()
|
||||
.iter_mut()
|
||||
.filter(|(cid, _)| cid == &id)
|
||||
.filter(|(cid, _)| *cid == &id)
|
||||
.flat_map(|(_, prop)| prop
|
||||
.iter_mut()
|
||||
.map(|obj| obj
|
||||
|
@ -553,7 +608,9 @@ impl HasLinkedDataInterface for Node {
|
|||
nodes
|
||||
}
|
||||
|
||||
fn ld_set_children(&mut self, id: Id, values: Vec<Self>) -> ResultSetMany {
|
||||
fn ld_set_children(&mut self, id: &str, values: Vec<Self>) -> ResultSetMany {
|
||||
let id = Id::from_string(id.to_string());
|
||||
|
||||
let indexed_objects = values
|
||||
.into_iter()
|
||||
.map(|value| {
|
||||
|
|
|
@ -2,21 +2,10 @@ use chrono::{DateTime, Local, TimeDelta};
|
|||
use json_ld::syntax::LangTagBuf;
|
||||
use mediatype::MediaType;
|
||||
use anyhow::Result as AResult;
|
||||
use json_ld::{Direction, Id};
|
||||
use json_ld::Direction;
|
||||
|
||||
mod jsonld;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! iri_id {
|
||||
($iri:literal) => {
|
||||
json_ld::Id::Valid(
|
||||
json_ld::ValidId::Iri(
|
||||
static_iref::iri!($iri).to_owned()
|
||||
)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
pub enum LangDir {
|
||||
Language(LangTagBuf),
|
||||
Direction(Direction),
|
||||
|
@ -31,48 +20,53 @@ pub type ResultSetOne = AResult<()>;
|
|||
pub type ResultSetMany = AResult<()>;
|
||||
|
||||
pub trait HasLinkedDataInterface: Sized {
|
||||
fn ld_has_type(&self, id: &Id) -> bool;
|
||||
fn ld_has_type(&self, id: &str) -> bool;
|
||||
|
||||
fn ld_get_string(&self, id: &Id) -> ResultGetOne<String>;
|
||||
fn ld_get_string_id(&self, id: &Id) -> ResultGetOne<String>;
|
||||
fn ld_get_mediatype(&self, id: &Id) -> ResultGetOne<MediaType>;
|
||||
fn ld_get_langtag(&self, id: &Id) -> ResultGetOne<LangTagBuf>;
|
||||
fn ld_get_u32(&self, id: &Id) -> ResultGetOne<u32>;
|
||||
fn ld_get_u64(&self, id: &Id) -> ResultGetOne<u64>;
|
||||
fn ld_get_timedelta(&self, id: &Id) -> ResultGetOne<TimeDelta>;
|
||||
fn ld_get_datetime_local(&self, id: &Id) -> ResultGetOne<DateTime<Local>>;
|
||||
fn ld_get_strings(&self, id: &Id) -> ResultGetMany<String>;
|
||||
fn ld_get_langstrings(&self, id: &Id) -> ResultGetMany<LangString>;
|
||||
fn ld_get_string(&self, id: &str) -> ResultGetOne<String>;
|
||||
fn ld_get_string_id(&self, id: &str) -> ResultGetOne<String>;
|
||||
fn ld_get_mediatype(&self, id: &str) -> ResultGetOne<MediaType>;
|
||||
fn ld_get_langtag(&self, id: &str) -> ResultGetOne<LangTagBuf>;
|
||||
fn ld_get_u32(&self, id: &str) -> ResultGetOne<u32>;
|
||||
fn ld_get_u64(&self, id: &str) -> ResultGetOne<u64>;
|
||||
fn ld_get_timedelta(&self, id: &str) -> ResultGetOne<TimeDelta>;
|
||||
fn ld_get_datetime_local(&self, id: &str) -> ResultGetOne<DateTime<Local>>;
|
||||
fn ld_get_strings(&self, id: &str) -> ResultGetMany<String>;
|
||||
fn ld_get_langstrings(&self, id: &str) -> ResultGetMany<LangString>;
|
||||
|
||||
fn ld_set_string(&mut self, id: Id, value: String) -> ResultSetOne;
|
||||
fn ld_set_string_id(&mut self, id: Id, value: String) -> ResultSetOne;
|
||||
fn ld_set_mediatype(&mut self, id: Id, value: MediaType) -> ResultSetOne;
|
||||
fn ld_set_langtag(&mut self, id: Id, value: LangTagBuf) -> ResultSetOne;
|
||||
fn ld_set_u32(&mut self, id: Id, value: u32) -> ResultSetOne;
|
||||
fn ld_set_u64(&mut self, id: Id, value: u64) -> ResultSetOne;
|
||||
fn ld_set_timedelta(&mut self, id: Id, value: TimeDelta) -> ResultSetOne;
|
||||
fn ld_set_datetime_local(&mut self, id: Id, value: DateTime<Local>) -> ResultSetOne;
|
||||
fn ld_set_strings(&mut self, id: Id, values: Vec<String>) -> ResultSetMany;
|
||||
fn ld_set_langstrings(&mut self, id: Id, values: Vec<LangString>) -> ResultSetMany;
|
||||
fn ld_set_string(&mut self, id: &str, value: String) -> ResultSetOne;
|
||||
fn ld_set_string_id(&mut self, id: &str, value: String) -> ResultSetOne;
|
||||
fn ld_set_mediatype(&mut self, id: &str, value: MediaType) -> ResultSetOne;
|
||||
fn ld_set_langtag(&mut self, id: &str, value: LangTagBuf) -> ResultSetOne;
|
||||
fn ld_set_u32(&mut self, id: &str, value: u32) -> ResultSetOne;
|
||||
fn ld_set_u64(&mut self, id: &str, value: u64) -> ResultSetOne;
|
||||
fn ld_set_timedelta(&mut self, id: &str, value: TimeDelta) -> ResultSetOne;
|
||||
fn ld_set_datetime_local(&mut self, id: &str, value: DateTime<Local>) -> ResultSetOne;
|
||||
fn ld_set_strings(&mut self, id: &str, values: Vec<String>) -> ResultSetMany;
|
||||
fn ld_set_langstrings(&mut self, id: &str, values: Vec<LangString>) -> ResultSetMany;
|
||||
|
||||
fn ld_get_child(&self, id: &Id) -> ResultGetOne<&Self>;
|
||||
fn ld_into_child_mut(&mut self, id: &Id) -> ResultGetOne<&mut Self>;
|
||||
fn ld_set_child(&mut self, id: Id, value: Self) -> ResultSetOne;
|
||||
fn ld_get_child(&self, id: &str) -> ResultGetOne<&Self>;
|
||||
fn ld_into_child_mut(&mut self, id: &str) -> ResultGetOne<&mut Self>;
|
||||
fn ld_set_child(&mut self, id: &str, value: Self) -> ResultSetOne;
|
||||
|
||||
fn ld_get_children(&self, id: &Id) -> ResultGetMany<&Self>;
|
||||
fn ld_into_children_mut(&mut self, id: &Id) -> ResultGetMany<&mut Self>;
|
||||
fn ld_set_children(&mut self, id: Id, values: Vec<Self>) -> ResultSetMany;
|
||||
fn ld_get_children(&self, id: &str) -> ResultGetMany<&Self>;
|
||||
fn ld_into_children_mut(&mut self, id: &str) -> ResultGetMany<&mut Self>;
|
||||
fn ld_set_children(&mut self, id: &str, values: Vec<Self>) -> ResultSetMany;
|
||||
}
|
||||
|
||||
pub type ResultConvert<W> = Option<W>;
|
||||
|
||||
pub trait IsLinkedDataReadWrapper<'b, B>
|
||||
pub trait IsLinkedDataWrapper
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
fn ld_type() -> &'static str;
|
||||
}
|
||||
|
||||
pub trait IsLinkedDataReadWrapper<'b, B>
|
||||
where
|
||||
Self: IsLinkedDataWrapper,
|
||||
B: HasLinkedDataInterface + 'b,
|
||||
{
|
||||
fn ld_type() -> &'static Id;
|
||||
|
||||
fn from_ref(backend: &'b B) -> Self;
|
||||
fn into_ref(self) -> &'b B;
|
||||
|
||||
|
@ -80,9 +74,8 @@ where
|
|||
where Other: IsLinkedDataReadWrapper<'b, B>
|
||||
{
|
||||
let backend = self.into_ref();
|
||||
let ld_type = Self::ld_type();
|
||||
|
||||
if !backend.ld_has_type(ld_type) {
|
||||
if !backend.ld_has_type(Self::ld_type()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
@ -94,11 +87,9 @@ where
|
|||
|
||||
pub trait IsLinkedDataWriteWrapper<'b, B>
|
||||
where
|
||||
Self: Sized,
|
||||
Self: IsLinkedDataWrapper,
|
||||
B: HasLinkedDataInterface + 'b,
|
||||
{
|
||||
fn ld_type() -> &'static Id;
|
||||
|
||||
fn from_mut(backend: &'b mut B) -> Self;
|
||||
fn into_mut(self) -> &'b mut B;
|
||||
|
||||
|
@ -106,9 +97,8 @@ where
|
|||
where Other: IsLinkedDataWriteWrapper<'b, B>
|
||||
{
|
||||
let backend = self.into_mut();
|
||||
let ld_type = Self::ld_type();
|
||||
|
||||
if !backend.ld_has_type(ld_type) {
|
||||
if !backend.ld_has_type(Self::ld_type()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -107,17 +107,25 @@ macro_rules! vocab {
|
|||
backend: &'b mut B
|
||||
}
|
||||
|
||||
impl<'b, B> $crate::linkeddata::IsLinkedDataWrapper for $vocab_ref<'b, B>
|
||||
where B: $crate::linkeddata::HasLinkedDataInterface,
|
||||
{
|
||||
fn ld_type() -> &'static str {
|
||||
$vocab_iri
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, B> $crate::linkeddata::IsLinkedDataWrapper for $vocab_mut<'b, B>
|
||||
where B: $crate::linkeddata::HasLinkedDataInterface,
|
||||
{
|
||||
fn ld_type() -> &'static str {
|
||||
$vocab_iri
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, B> $crate::linkeddata::IsLinkedDataReadWrapper<'b, B> for $vocab_ref<'b, B>
|
||||
where B: $crate::linkeddata::HasLinkedDataInterface,
|
||||
{
|
||||
|
||||
#[inline(always)]
|
||||
fn ld_type() -> &'static json_ld::Id {
|
||||
static id: json_ld::Id = $crate::iri_id! ( $vocab_iri );
|
||||
|
||||
&id
|
||||
}
|
||||
|
||||
fn from_ref(backend: &'b B) -> Self {
|
||||
Self {
|
||||
backend
|
||||
|
@ -132,12 +140,6 @@ macro_rules! vocab {
|
|||
impl<'b, B> $crate::linkeddata::IsLinkedDataWriteWrapper<'b, B> for $vocab_mut<'b, B>
|
||||
where B: $crate::linkeddata::HasLinkedDataInterface,
|
||||
{
|
||||
fn ld_type() -> &'static json_ld::Id {
|
||||
static id: json_ld::Id = $crate::iri_id! ( $vocab_iri );
|
||||
|
||||
&id
|
||||
}
|
||||
|
||||
fn from_mut(backend: &'b mut B) -> Self {
|
||||
Self {
|
||||
backend
|
||||
|
@ -156,9 +158,7 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $one_get_meta ] )*
|
||||
pub fn $one_get_name(&'b self) -> $crate::linkeddata::ResultGetOne<$one_type> {
|
||||
self.backend.$one_get_via(
|
||||
& $crate::iri_id!( $one_iri )
|
||||
)
|
||||
self.backend.$one_get_via($one_iri)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
@ -169,19 +169,14 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $one_get_meta ] )*
|
||||
pub fn $one_get_name(&'b self) -> $crate::linkeddata::ResultGetOne<$one_type> {
|
||||
self.backend.$one_get_via(
|
||||
& $crate::iri_id!( $one_iri )
|
||||
)
|
||||
self.backend.$one_get_via($one_iri)
|
||||
}
|
||||
)*
|
||||
|
||||
$(
|
||||
$( #[ $one_set_meta ] )*
|
||||
pub fn $one_set_name(&'b mut self, value: $one_type) -> $crate::linkeddata::ResultSetOne {
|
||||
self.backend.$one_set_via(
|
||||
$crate::iri_id!( $one_iri ),
|
||||
value
|
||||
)
|
||||
self.backend.$one_set_via($one_iri, value)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
@ -194,9 +189,7 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $many_get_meta ] )*
|
||||
pub fn $many_get_name(&'b self) -> $crate::linkeddata::ResultGetMany<$many_type> {
|
||||
self.backend.$many_get_via(
|
||||
& $crate::iri_id!( $many_iri )
|
||||
)
|
||||
self.backend.$many_get_via($many_iri)
|
||||
}
|
||||
),*
|
||||
}
|
||||
|
@ -207,19 +200,14 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $many_get_meta ] )*
|
||||
pub fn $many_get_name(&'b self) -> $crate::linkeddata::ResultGetMany<$many_type> {
|
||||
self.backend.$many_get_via(
|
||||
& $crate::iri_id!( $many_iri )
|
||||
)
|
||||
self.backend.$many_get_via($many_iri)
|
||||
}
|
||||
),*
|
||||
|
||||
$(
|
||||
$( #[ $many_set_meta ] )*
|
||||
pub fn $many_set_name(&'b mut self, values: Vec<$many_type>) -> $crate::linkeddata::ResultSetMany {
|
||||
self.backend.$many_set_via(
|
||||
$crate::iri_id!( $many_iri ),
|
||||
values
|
||||
)
|
||||
self.backend.$many_set_via($many_iri, values)
|
||||
}
|
||||
),*
|
||||
}
|
||||
|
@ -232,9 +220,7 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $child_get_meta ] )*
|
||||
pub fn $child_get_name(&'b self) -> $crate::linkeddata::ResultGetOne<&'b B> {
|
||||
self.backend.ld_get_child(
|
||||
& $crate::iri_id!( $child_iri )
|
||||
)
|
||||
self.backend.ld_get_child($child_iri)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
@ -245,28 +231,21 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $child_get_meta ] )*
|
||||
pub fn $child_get_name(&'b self) -> $crate::linkeddata::ResultGetOne<&'b B> {
|
||||
self.backend.ld_get_child(
|
||||
& $crate::iri_id!( $child_iri )
|
||||
)
|
||||
self.backend.ld_get_child($child_iri)
|
||||
}
|
||||
),*
|
||||
|
||||
$(
|
||||
$( #[ $child_into_meta ] )*
|
||||
pub fn $child_into_name(self) -> $crate::linkeddata::ResultGetOne<&'b mut B> {
|
||||
self.backend.ld_into_child_mut(
|
||||
& $crate::iri_id!( $child_iri )
|
||||
)
|
||||
self.backend.ld_into_child_mut($child_iri)
|
||||
}
|
||||
),*
|
||||
|
||||
$(
|
||||
$( #[ $child_into_meta ] )*
|
||||
pub fn $child_set_name(&'b mut self, values: Vec<B>) -> $crate::linkeddata::ResultSetOne {
|
||||
self.backend.ld_set_child(
|
||||
$crate::iri_id!( $child_iri ),
|
||||
values
|
||||
)
|
||||
self.backend.ld_set_child($child_iri, values)
|
||||
}
|
||||
),*
|
||||
}
|
||||
|
@ -279,9 +258,7 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $children_get_meta ] )*
|
||||
pub fn $children_get_name(&'b self) -> $crate::linkeddata::ResultGetMany<&'b B> {
|
||||
self.backend.ld_get_children(
|
||||
& $crate::iri_id!( $children_iri )
|
||||
)
|
||||
self.backend.ld_get_children($children_iri)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
@ -292,28 +269,21 @@ macro_rules! vocab {
|
|||
$(
|
||||
$( #[ $children_get_meta ] )*
|
||||
pub fn $children_get_name(&'b self) -> $crate::linkeddata::ResultGetMany<&'b B> {
|
||||
self.backend.ld_get_children(
|
||||
& $crate::iri_id!( $children_iri )
|
||||
)
|
||||
self.backend.ld_get_children($children_iri)
|
||||
}
|
||||
)*
|
||||
|
||||
$(
|
||||
$( #[ $children_into_meta ] )*
|
||||
pub fn $children_into_name(self) -> $crate::linkeddata::ResultGetMany<&'b mut B> {
|
||||
self.backend.ld_into_children_mut(
|
||||
& $crate::iri_id!( $children_iri )
|
||||
)
|
||||
self.backend.ld_into_children_mut($children_iri)
|
||||
}
|
||||
)*
|
||||
|
||||
$(
|
||||
$( #[ $children_into_meta ] )*
|
||||
pub fn $children_set_name(&'b mut self, values: Vec<B>) -> $crate::linkeddata::ResultSetMany {
|
||||
self.backend.ld_set_children(
|
||||
$crate::iri_id!( $children_iri ),
|
||||
values
|
||||
)
|
||||
self.backend.ld_set_children($children_iri, values)
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue