Skip to content

An abstraction crate to convert iterators on the fly.

License

Notifications You must be signed in to change notification settings

watcol/conversion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conversion

status crates.io Downloads Downloads (latest) License Lint Test

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.