Dereference

Trait Dereference 

Source
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 can be created that contains a simple Url, and with a dereference implementation, can be passed to a Repository to fetch the T object it represents

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§

Source

type Output: DeserializeOwned

The Concrete Type produced by dereferencing

Required Methods§

Source

fn url(&self) -> &Url

Fetch the URL that describes the object

Implementations on Foreign Types§

Source§

impl<'a, T> Dereference for &'a T
where T: Dereference,

Source§

type Output = <T as Dereference>::Output

Source§

fn url(&self) -> &Url

Source§

impl<'a, T> Dereference for &'a mut T
where T: Dereference,

Source§

type Output = <T as Dereference>::Output

Source§

fn url(&self) -> &Url

Source§

impl<T> Dereference for Box<T>
where T: Dereference,

Source§

type Output = <T as Dereference>::Output

Source§

fn url(&self) -> &Url

Source§

impl<T> Dereference for Rc<T>
where T: Dereference,

Source§

type Output = <T as Dereference>::Output

Source§

fn url(&self) -> &Url

Source§

impl<T> Dereference for Arc<T>
where T: Dereference,

Source§

type Output = <T as Dereference>::Output

Source§

fn url(&self) -> &Url

Implementors§