Crates.io | lz-str |
lib.rs | lz-str |
version | 0.2.1 |
source | src |
created_at | 2021-01-23 08:01:24.451726 |
updated_at | 2022-10-29 02:49:22.174044 |
description | A port of lz-string to Rust |
homepage | https://github.com/adumbidiot/lz-str-rs |
repository | https://github.com/adumbidiot/lz-str-rs |
max_upload_size | |
id | 345553 |
size | 111,409 |
A port of lz-string to Rust.
Add the following to your Cargo.toml
file:
[dependencies]
lz-str = "0.1.0"
// The demonstrated functions correspond with `LZString.compress` and `LZString.decompress` from the JS version.
fn main() {
let data = "The quick brown fox jumps over the lazy dog";
// Compress the data. This cannot fail.
let compressed_data = lz_str::compress(data);
// Decompress the data.
// This may return `Option::None` if it fails.
// Make sure to do error-checking in a real application to prevent crashes!
let decompressed_data =
lz_str::decompress(compressed_data).expect("`compressed_data` is invalid");
// The decompressed_data should be the same as data, except encoded as UTF16.
// We undo that here.
// In a real application,
// you will want to do error checking to prevent users from causing crashes with invalid data.
let decompressed_data =
String::from_utf16(&decompressed_data).expect("`decompressed_data` is not valid UTF16");
assert!(data == decompressed_data);
}
See the examples directory for more examples.
rustc-hash
: This feature will replace some internal maps' hashers with rustc-hash,
boosting performance at the cost of not using a DOS-resistant hasher.
cargo test
cargo bench
adumbidiot (Nathaniel Daniel)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.