Skip to content

Commit

Permalink
ZeroTrie: Add as_borrowed_slice and AsRef impl (#4381)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Nov 30, 2023
1 parent c53601e commit 8366ae1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions experimental/zerotrie/src/zerotrie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,20 @@ macro_rules! impl_zerotrie_subtype {
pub fn as_borrowed(&self) -> &$name<[u8]> {
$name::from_bytes(self.store.as_ref())
}
/// Returns a trie with a store borrowing from this trie.
#[inline]
pub fn as_borrowed_slice(&self) -> $name<&[u8]> {
$name::from_store(self.store.as_ref())
}
}
impl<Store> AsRef<$name<[u8]>> for $name<Store>
where
Store: AsRef<[u8]> + ?Sized,
{
#[inline]
fn as_ref(&self) -> &$name<[u8]> {
self.as_borrowed()
}
}
#[cfg(feature = "alloc")]
impl<Store> $name<Store>
Expand Down

0 comments on commit 8366ae1

Please sign in to comment.