support denoting entry entities in decomposed format (adding URLs)
This commit is contained in:
parent
686020e579
commit
b5a90ce57c
2 changed files with 22 additions and 3 deletions
|
@ -8,11 +8,18 @@ use std::io::{Cursor, Write};
|
|||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct InEntry {
|
||||
pub entity: Option<Address>,
|
||||
pub entity: Option<InAddress>,
|
||||
pub attribute: String,
|
||||
pub value: EntryValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum InAddress {
|
||||
Address(String),
|
||||
Components { t: String, c: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Entry {
|
||||
pub entity: Address,
|
||||
|
@ -123,8 +130,19 @@ impl TryFrom<InEntry> for Entry {
|
|||
|
||||
fn try_from(in_entry: InEntry) -> Result<Self, Self::Error> {
|
||||
match in_entry.entity {
|
||||
Some(entity) => Ok(Entry {
|
||||
entity,
|
||||
Some(address) => Ok(Entry {
|
||||
entity: match address {
|
||||
InAddress::Address(address) => address.parse()?,
|
||||
InAddress::Components { t, c } => {
|
||||
// I absolutely cannot handle serde magic right now
|
||||
// TODO: make this automatically derive from `Address` definition
|
||||
match t.as_str() {
|
||||
"Attribute" => Address::Attribute(c),
|
||||
"Url" => Address::Url(c),
|
||||
_ => c.parse()?,
|
||||
}
|
||||
}
|
||||
},
|
||||
attribute: in_entry.attribute,
|
||||
value: in_entry.value,
|
||||
}),
|
||||
|
|
|
@ -217,6 +217,7 @@ pub async fn get_object(
|
|||
|
||||
debug!("{:?}", result);
|
||||
|
||||
// TODO: make this automatically derive from `Address` definition
|
||||
let (entity_type, entity_content) = match address {
|
||||
Address::Hash(_) => ("Hash", None),
|
||||
Address::Uuid(_) => ("Uuid", None),
|
||||
|
|
Loading…
Reference in a new issue