Cache

Trait Cache 

Source
pub trait Cache<Id: ?Sized> {
    type Storage: AsRef<str>;

    // Required methods
    fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, impl Debug>;
    fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>;
}
Expand description

A trait implemented by Source caches.

Required Associated Types§

Source

type Storage: AsRef<str>

The type used to store the string data for this cache.

Alternative types other than String can be used, but at the moment, the storage must be contiguous. A primary use case for this is to use a reference-counted string instead of copying the whole contents into a Source.

Required Methods§

Source

fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, impl Debug>

Fetch the Source identified by the given ID, if possible.

Source

fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>

Display the given ID. as a single inline value.

This function may make use of attributes from the Fmt trait.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<C: Cache<Id>, Id: ?Sized> Cache<Id> for &mut C

Source§

type Storage = <C as Cache<Id>>::Storage

Source§

fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, impl Debug>

Source§

fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>

Source§

impl<C: Cache<Id>, Id: ?Sized> Cache<Id> for Box<C>

Source§

type Storage = <C as Cache<Id>>::Storage

Source§

fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, impl Debug>

Source§

fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>

Source§

impl<I: AsRef<str>, Id: Display + Eq> Cache<Id> for (Id, &Source<I>)

Source§

type Storage = I

Source§

fn fetch(&mut self, id: &Id) -> Result<&Source<I>, impl Debug>

Source§

fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>

Source§

impl<I: AsRef<str>, Id: Display + Eq> Cache<Id> for (Id, Source<I>)

Source§

type Storage = I

Source§

fn fetch(&mut self, id: &Id) -> Result<&Source<I>, impl Debug>

Source§

fn display<'a>(&self, id: &'a Id) -> Option<impl Display + 'a>

Implementors§

Source§

impl Cache<Path> for FileCache

Source§

impl<I: AsRef<str>> Cache<()> for &Source<I>

Source§

impl<I: AsRef<str>> Cache<()> for Source<I>

Source§

impl<Id: Display + Hash + PartialEq + Eq + Clone, F, I, E> Cache<Id> for FnCache<Id, F, I>
where I: AsRef<str>, E: Debug, F: for<'a> FnMut(&'a Id) -> Result<I, E>,