add len() and from_bytes()

This commit is contained in:
abbie 2022-03-13 17:32:55 +00:00
parent ed0da9da59
commit 2267e441f7
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 14 additions and 1 deletions

View file

@ -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 <colean@colean.cc>"]
license = "LGPL-3.0-or-later"

View file

@ -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)
}
}