aboutsummaryrefslogtreecommitdiff
path: root/ebml/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-01-13 20:21:45 +0100
committermetamuffin <metamuffin@disroot.org>2023-01-13 20:21:45 +0100
commit36e91c20eb59e76d5aeb35e644e7fb391f346dc6 (patch)
tree45ea6dd876ec3af8e38857bce6d26faf630011de /ebml/src/lib.rs
parent8fc4b9792044d82e729e8b4ef993c6391d711c5b (diff)
downloadjellything-36e91c20eb59e76d5aeb35e644e7fb391f346dc6.tar
jellything-36e91c20eb59e76d5aeb35e644e7fb391f346dc6.tar.bz2
jellything-36e91c20eb59e76d5aeb35e644e7fb391f346dc6.tar.zst
proc macro works
Diffstat (limited to 'ebml/src/lib.rs')
-rw-r--r--ebml/src/lib.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/ebml/src/lib.rs b/ebml/src/lib.rs
index 116b8e2..acebae3 100644
--- a/ebml/src/lib.rs
+++ b/ebml/src/lib.rs
@@ -47,3 +47,34 @@ impl EbmlReader {
})
}
}
+
+pub trait ValueFromBuf: Sized {
+ fn from_buf(buf: &[u8]) -> anyhow::Result<Self>;
+}
+
+impl ValueFromBuf for u64 {
+ fn from_buf(buf: &[u8]) -> anyhow::Result<Self> {
+ if buf.len() != 8 {
+ bail!("u64 is not 64 bits long")
+ }
+ Ok((buf[0] as u64) << 24
+ | (buf[1] as u64) << 16
+ | (buf[2] as u64) << 8
+ | (buf[3] as u64) << 0)
+ }
+}
+impl ValueFromBuf for Vec<u8> {
+ fn from_buf(buf: &[u8]) -> anyhow::Result<Self> {
+ Ok(buf.to_vec())
+ }
+}
+impl ValueFromBuf for String {
+ fn from_buf(buf: &[u8]) -> anyhow::Result<Self> {
+ Ok(String::from_utf8(Vec::from(buf))?)
+ }
+}
+impl ValueFromBuf for Master {
+ fn from_buf(_buf: &[u8]) -> anyhow::Result<Self> {
+ Ok(Master::Start)
+ }
+}