introduce dechunk and rechunk as well as change punctuation error in docs
This commit is contained in:
parent
9c5290813a
commit
8a5a828dbc
2 changed files with 31 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "clippet"
|
name = "clippet"
|
||||||
description = "Provides a teeny way to have some nice byte structures that's easy to use."
|
description = "Provides a teeny way to have some nice byte structures that's easy to use."
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Celeste <colean@colean.cc>"]
|
authors = ["Celeste <colean@colean.cc>"]
|
||||||
license = "LGPL-3.0-or-later"
|
license = "LGPL-3.0-or-later"
|
||||||
|
|
31
src/lib.rs
31
src/lib.rs
|
@ -144,7 +144,7 @@ impl Clippet {
|
||||||
return clip
|
return clip
|
||||||
|
|
||||||
}
|
}
|
||||||
/// Consumes the Clippet, combines all of it's byte sequences and outputs them as a String literal.
|
/// Consumes the Clippet, combines all of its byte sequences and outputs them as a String literal.
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// let data = Clippet::from_string("Hello, World!", 512);
|
/// let data = Clippet::from_string("Hello, World!", 512);
|
||||||
|
@ -163,4 +163,33 @@ impl Clippet {
|
||||||
}
|
}
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
/// Replaces the Clippet with one that has all of its data in one chunk.
|
||||||
|
/// The label is retained, the data is not modified apart from being dechunked.
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// let data = Clippet::from_string("HelloWorld", 5); // [b"Hello", b"World"]
|
||||||
|
/// let data = data.dechunk(); // [b"HelloWorld"]
|
||||||
|
/// ```
|
||||||
|
pub fn dechunk(self) -> Clippet {
|
||||||
|
// Retain label.
|
||||||
|
let label = self.label.to_string();
|
||||||
|
let data = self.combine();
|
||||||
|
let clip = Clippet { label: label, size: 1, data: vec![BytesMut::from(data.as_str())] };
|
||||||
|
return clip
|
||||||
|
}
|
||||||
|
/// Combines the Clippet and then remakes it, retaining the label, with the specified max chunk size.
|
||||||
|
/// No data is modified.
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// let longstring = "long string bla bla bla..."; // Pretend this is 2KB large!
|
||||||
|
/// let data = Clippet::from_string(longstring, 512); // size: 4
|
||||||
|
/// let data = data.rechunk(1024) // size: 2
|
||||||
|
/// ```
|
||||||
|
pub fn rechunk(self, size: usize) -> Clippet {
|
||||||
|
let label = self.label.to_string();
|
||||||
|
let data = self.combine();
|
||||||
|
let mut clip = Clippet::from_string(&data, size);
|
||||||
|
if label != "".to_string() { clip.label = label; }
|
||||||
|
return clip
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue