pub trait Dereference {
type Output: DeserializeOwned;
// Required method
fn url(&self) -> &Url;
}
Expand description
A trait describing the input and output types of a dereference operation
For example, a type ObjectId
use apub_core::repo::{Dereference, Repo};
use std::borrow::Cow;
use url::Url;
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
struct SomeId<'a>(Cow<'a, Url>);
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct SomeObject {
id: SomeId<'static>,
content: String,
}
impl<'a> Dereference for SomeId<'a> {
type Output = SomeObject;
fn url(&self) -> &Url {
&self.0
}
}
async fn fetch<R: Repo>(repo: &R, url: &Url) -> Option<SomeObject> {
let id = SomeId(Cow::Borrowed(url));
repo.fetch(id, ()).await.ok()?
}
Required Associated Types§
Sourcetype Output: DeserializeOwned
type Output: DeserializeOwned
The Concrete Type produced by dereferencing