conversion

Crates.ioconversion
lib.rsconversion
version0.1.0
sourcesrc
created_at2022-01-16 10:25:38.265397
updated_at2022-01-16 10:25:38.265397
descriptionAn abstraction crate to convert iterators on the fly.
homepage
repositoryhttps://github.com/watcol/convert-iterator
max_upload_size
id514718
size67,424
watcol (watcol)

documentation

README

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.

Commit count: 0

cargo fmt