2024-03-19 05:15:41 +01:00
|
|
|
use crate::strenum;
|
|
|
|
|
|
|
|
strenum! {
|
|
|
|
pub enum LinkType {
|
|
|
|
Link,
|
2024-03-19 22:47:52 +01:00
|
|
|
Mention;
|
|
|
|
};
|
2024-03-19 05:15:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Link : super::Base {
|
2024-03-19 01:00:44 +01:00
|
|
|
fn href(&self) -> &str;
|
|
|
|
fn rel(&self) -> Option<&str> { None }
|
|
|
|
fn media_type(&self) -> Option<&str> { None } // also in obj
|
|
|
|
fn name(&self) -> Option<&str> { None } // also in obj
|
|
|
|
fn hreflang(&self) -> Option<&str> { None }
|
|
|
|
fn height(&self) -> Option<&str> { None }
|
|
|
|
fn width(&self) -> Option<&str> { None }
|
|
|
|
fn preview(&self) -> Option<&str> { None } // also in obj
|
|
|
|
}
|
|
|
|
|
2024-03-20 05:44:10 +01:00
|
|
|
pub trait LinkMut : super::BaseMut {
|
|
|
|
fn set_href(&mut self, href: &str) -> &mut Self;
|
|
|
|
fn set_rel(&mut self, val: Option<&str>) -> &mut Self;
|
|
|
|
fn set_media_type(&mut self, val: Option<&str>) -> &mut Self; // also in obj
|
|
|
|
fn set_name(&mut self, val: Option<&str>) -> &mut Self; // also in obj
|
|
|
|
fn set_hreflang(&mut self, val: Option<&str>) -> &mut Self;
|
|
|
|
fn set_height(&mut self, val: Option<&str>) -> &mut Self;
|
|
|
|
fn set_width(&mut self, val: Option<&str>) -> &mut Self;
|
|
|
|
fn set_preview(&mut self, val: Option<&str>) -> &mut Self; // also in obj
|
|
|
|
}
|
|
|
|
|
2024-03-19 01:00:44 +01:00
|
|
|
impl Link for String {
|
|
|
|
fn href(&self) -> &str {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Link for serde_json::Value {
|
|
|
|
// TODO this is unchecked and can panic
|
|
|
|
fn href(&self) -> &str {
|
|
|
|
match self {
|
|
|
|
serde_json::Value::String(x) => x,
|
|
|
|
serde_json::Value::Object(map) =>
|
|
|
|
map.get("href")
|
|
|
|
.unwrap()
|
|
|
|
.as_str()
|
|
|
|
.unwrap(),
|
|
|
|
_ => panic!("invalid value for Link"),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ... TODO!
|
|
|
|
}
|