1 unstable release
0.1.0 | Jan 16, 2022 |
---|
#2079 in Encoding
68KB
1.5K
SLoC
Conversion
An abstraction crate to convert iterators on the fly.
Demo
use conversion::converter::encoding::utf8::{UTF8Decoder, UTF8Encoder};
use conversion::converter::IterConverter;
use conversion::iter::{ConvertedIterator, ConvertedTryIterator};
// An original byte string.
let iter = b"stra\xc3\x9fe".into_iter().cloned();
// Decoding UTF-8 byte string.
let decoded = ConvertedIterator::new(iter, UTF8Decoder::new());
assert_eq!(Ok(String::from("straße")), decoded.clone().collect());
// Convert to uppercase. (use ConvertedTryIterator because `decoded` returns Result items.)
let uppered = ConvertedTryIterator::new(decoded, IterConverter::new(char::to_uppercase));
assert_eq!(Ok(String::from("STRASSE")), uppered.clone().collect());
// Re-encode the value.
let encoded = ConvertedTryIterator::new(uppered, UTF8Encoder::new());
assert_eq!(Ok(b"STRASSE".to_vec()), encoded.collect());
Documentation
API Documentations are available on here.
Usage
Add to your Cargo.toml
:
[dependencies]
conversion = "0.1.0"
conversion = { version = "0.1.0", features = ["async"] } # If you want to use asynchronous stream.
conversion = { version = "0.1.0", default-features = false } # no_std support.
License
This program is licensed under the MIT license. See LICENSE for details.
Dependencies
~18KB