summaryrefslogtreecommitdiff
path: root/src/util/buffer.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-06-26 13:57:21 +0200
committerLaurenz <laurmaedje@gmail.com>2023-06-27 18:40:17 +0200
commit7b92bd7c340d9f9c094ed2fa57912049317d9b20 (patch)
treeb91399526ba94d87309d09d864df2935dd7a4d0a /src/util/buffer.rs
parent9c7f31870b4e1bf37df79ebbe1df9a56df83d878 (diff)
Basic package management
Diffstat (limited to 'src/util/buffer.rs')
-rw-r--r--src/util/buffer.rs59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/util/buffer.rs b/src/util/buffer.rs
deleted file mode 100644
index 23fb9802..00000000
--- a/src/util/buffer.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-use std::borrow::Cow;
-use std::fmt::{self, Debug, Formatter};
-use std::ops::Deref;
-use std::sync::Arc;
-
-use comemo::Prehashed;
-
-/// A shared buffer that is cheap to clone and hash.
-#[derive(Clone, Hash, Eq, PartialEq)]
-pub struct Buffer(Arc<Prehashed<Cow<'static, [u8]>>>);
-
-impl Buffer {
- /// Create a buffer from a static byte slice.
- pub fn from_static(slice: &'static [u8]) -> Self {
- Self(Arc::new(Prehashed::new(Cow::Borrowed(slice))))
- }
-
- /// Return a view into the buffer.
- pub fn as_slice(&self) -> &[u8] {
- self
- }
-
- /// Return a copy of the buffer as a vector.
- pub fn to_vec(&self) -> Vec<u8> {
- self.0.to_vec()
- }
-}
-
-impl From<&[u8]> for Buffer {
- fn from(slice: &[u8]) -> Self {
- Self(Arc::new(Prehashed::new(slice.to_vec().into())))
- }
-}
-
-impl From<Vec<u8>> for Buffer {
- fn from(vec: Vec<u8>) -> Self {
- Self(Arc::new(Prehashed::new(vec.into())))
- }
-}
-
-impl Deref for Buffer {
- type Target = [u8];
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
-}
-
-impl AsRef<[u8]> for Buffer {
- fn as_ref(&self) -> &[u8] {
- self
- }
-}
-
-impl Debug for Buffer {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.pad("Buffer(..)")
- }
-}