strings bro
This commit is contained in:
parent
f51e4ac941
commit
37bd4f2166
2 changed files with 14 additions and 1 deletions
|
@ -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.7"
|
||||
version = "0.1.8"
|
||||
edition = "2021"
|
||||
authors = ["Celeste <colean@colean.cc>"]
|
||||
license = "MPL-2.0"
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -84,6 +84,19 @@ impl Clippet {
|
|||
pub fn get_data(&self, index: usize) -> BytesMut {
|
||||
return self.data[index].to_owned()
|
||||
}
|
||||
/// Takes an indexed byte sequence and returns it as a String.
|
||||
/// ```no_run
|
||||
/// let bytes = BytesMut::from("Hello, world!");
|
||||
/// let mut data = Clippet { ... };
|
||||
/// data.add_bytes(bytes);
|
||||
/// assert_eq!(data.get_as_string(0), "Hello, world!");
|
||||
/// ```
|
||||
pub fn get_as_string(&self, index: usize) -> String {
|
||||
let bytes = self.get_data(index);
|
||||
let y = bytes.as_ref();
|
||||
let x = String::from_utf8_lossy(y).to_string();
|
||||
return x
|
||||
}
|
||||
/// Takes a filename and splits it into sequences of bytes within a Clippet.
|
||||
/// It is recommended to use smaller byte sequences, however this is user-configurable.
|
||||
///
|
||||
|
|
Reference in a new issue