Skip to content

Commit

Permalink
Allow Caches to return a name borrowed from themselves
Browse files Browse the repository at this point in the history
This is useful when the name comes not from the handle, but from the cache itself.
For example, if the cache is a sort of `Vec<{name: String, contents: Source<...>}>`
(the the handles are `usize`s).
  • Loading branch information
ISSOtm committed Sep 16, 2024
1 parent 41b562a commit 29411f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub trait Cache<Id: ?Sized> {
///
/// This function may make use of attributes from the [`Fmt`] trait.
// TODO: Don't box
fn display<'a>(&self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>>;
fn display<'a>(&'a self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>>;
}

impl<'b, C: Cache<Id>, Id: ?Sized> Cache<Id> for &'b mut C {
Expand All @@ -32,7 +32,7 @@ impl<'b, C: Cache<Id>, Id: ?Sized> Cache<Id> for &'b mut C {
fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, Box<dyn fmt::Debug + '_>> {
C::fetch(self, id)
}
fn display<'a>(&self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>> {
fn display<'a>(&'a self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>> {
C::display(self, id)
}
}
Expand All @@ -43,7 +43,7 @@ impl<C: Cache<Id>, Id: ?Sized> Cache<Id> for Box<C> {
fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, Box<dyn fmt::Debug + '_>> {
C::fetch(self, id)
}
fn display<'a>(&self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>> {
fn display<'a>(&'a self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>> {
C::display(self, id)
}
}
Expand Down

0 comments on commit 29411f5

Please sign in to comment.