Crates.io | conversion |
lib.rs | conversion |
version | 0.1.0 |
source | src |
created_at | 2022-01-16 10:25:38.265397 |
updated_at | 2022-01-16 10:25:38.265397 |
description | An abstraction crate to convert iterators on the fly. |
homepage | |
repository | https://github.com/watcol/convert-iterator |
max_upload_size | |
id | 514718 |
size | 67,424 |
An abstraction crate to convert iterators on the fly.
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());
API Documentations are available on here.
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.
This program is licensed under the MIT license. See LICENSE for details.