From 2267e441f7ba2c998119ad3b4e2a2b0b00cef01f Mon Sep 17 00:00:00 2001 From: Celeste Date: Sun, 13 Mar 2022 17:32:55 +0000 Subject: [PATCH] add len() and from_bytes() --- Cargo.toml | 2 +- src/lib.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8b47a34..e095e3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "clippet" description = "Provides a teeny way to have some nice byte structures that's easy to use." -version = "0.1.2" +version = "0.1.3" edition = "2021" authors = ["Celeste "] license = "LGPL-3.0-or-later" diff --git a/src/lib.rs b/src/lib.rs index cafebda..241e2fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,4 +107,17 @@ impl Clippet { return clip } + /// Takes a sequence of bytes and wraps it around a Clippet structure. + /// + /// ```no_run + /// let data = Clippet::from_bytes(foo); + /// ``` + pub fn from_bytes(bytes: BytesMut) -> Clippet { + let clip = Clippet { label: "".to_string(), size: 1, data: vec![bytes] }; + return clip + } + /// Alias of `get_size(&self)` + pub fn len(&self) -> i32 { + return get_size(&self) + } }