summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-21 23:18:56 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-21 23:18:56 +0100
commitb934a2fd83d63fc115c01f959e888c7bc1aa87e4 (patch)
treef99e2e867733a2b37e3df2db24edf61d438adeb5 /src
parent27bb5e8d22f6fe466cecc80bcbad9aec63b2a8f7 (diff)
Embed standard fonts in binaryv23-03-21-2
Diffstat (limited to 'src')
-rw-r--r--src/util/buffer.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/util/buffer.rs b/src/util/buffer.rs
index da12b6cb..23fb9802 100644
--- a/src/util/buffer.rs
+++ b/src/util/buffer.rs
@@ -1,3 +1,4 @@
+use std::borrow::Cow;
use std::fmt::{self, Debug, Formatter};
use std::ops::Deref;
use std::sync::Arc;
@@ -6,9 +7,14 @@ use comemo::Prehashed;
/// A shared buffer that is cheap to clone and hash.
#[derive(Clone, Hash, Eq, PartialEq)]
-pub struct Buffer(Arc<Prehashed<Vec<u8>>>);
+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
@@ -22,13 +28,13 @@ impl Buffer {
impl From<&[u8]> for Buffer {
fn from(slice: &[u8]) -> Self {
- Self(Arc::new(Prehashed::new(slice.to_vec())))
+ 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)))
+ Self(Arc::new(Prehashed::new(vec.into())))
}
}