From b0b31d9159f12107e59cac45c0fe2197fbb7efb6 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Wed, 29 Nov 2023 19:34:35 -0700 Subject: [PATCH] Add as_borrowed_slice and AsRef impl. Need to bikeshed the name. --- experimental/zerotrie/src/zerotrie.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/experimental/zerotrie/src/zerotrie.rs b/experimental/zerotrie/src/zerotrie.rs index f319ed9324a..deedcb81443 100644 --- a/experimental/zerotrie/src/zerotrie.rs +++ b/experimental/zerotrie/src/zerotrie.rs @@ -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 AsRef<$name<[u8]>> for $name + where + Store: AsRef<[u8]> + ?Sized, + { + #[inline] + fn as_ref(&self) -> &$name<[u8]> { + self.as_borrowed() + } } #[cfg(feature = "alloc")] impl $name