| 1 | # encode_unicode |
| 2 | |
| 3 | UTF-8 and UTF-16 character types, iterators and related methods for `char`, `u8` and `u16`. |
| 4 | |
| 5 | [](https://crates.io/crates/encode_unicode/) |
| 6 | |
| 7 | ## Features |
| 8 | |
| 9 | * **[`Utf8Char`](https://docs.rs/encode_unicode/latest/encode_unicode/struct.Utf8Char.html)**: |
| 10 | A `char` stored as UTF-8. Can be borrowed as a `str` or `u8` slice. |
| 11 | * **[`Utf16Char`](https://docs.rs/encode_unicode/latest/encode_unicode/struct.Utf16Char.html)**: |
| 12 | A `char` stored as UTF-16. Can be borrowed as an `u16` slice. |
| 13 | * [Conversion methods on `char`](https://docs.rs/encode_unicode/latest/encode_unicode/trait.CharExt.html): |
| 14 | * to and from UTF-8 as `[u8; 4]` or slice. |
| 15 | * to and from UTF-16 as `(u16, Option<u16>)` or slice. |
| 16 | * [Iterator adapters](https://docs.rs/encode_unicode/latest/encode_unicode/trait.IterExt.html) |
| 17 | for converting betwenn `u8`s and `Utf8Char`s or `u16`s and `Utf16Char`s. |
| 18 | * Optimized [slice-based decoding iterators](https://docs.rs/encode_unicode/latest/encode_unicode/trait.SliceExt.html). |
| 19 | * [Precise errors when decoding a char from UTF-8, UTF-16 or `u32` fails](http://docs.rs/encode_unicode/latest/encode_unicode/error/index.html). |
| 20 | * Utility methods on [`u8`](https://docs.rs/encode_unicode/latest/encode_unicode/trait.U8UtfExt.html) |
| 21 | and [`u16`](https://docs.rs/encode_unicode/latest/encode_unicode/trait.U16UtfExt.html). |
| 22 | |
| 23 | The minimum supported version of Rust is 1.15, |
| 24 | older versions might work now but can break with a minor update. |
| 25 | |
| 26 | ## Optional features |
| 27 | |
| 28 | * `#![no_std]`-mode: There are a few differences: |
| 29 | * `Error` doesn't exist, but `description()` is made available as an inherent impl. |
| 30 | * `Extend`/`FromIterator`-implementations for `String`/`Vec<u8>`/`Vec<u16>` are missing. |
| 31 | * There is no `io`, so `Utf8Iterator` and `Utf8CharSplitter` doesn't implement `Read`. |
| 32 | This feature is enabled by setting `default-features=false` in `Cargo.toml`: |
| 33 | `encode_unicode = {version="0.3.4", default-features=false}`. |
| 34 | * Integration with the [ascii](https://tomprogrammer.github.io/rust-ascii/ascii/index.html) crate: |
| 35 | Convert `Utf8Char` and `Utf16Char` to and from [ascii::`AsciiChar`](https://tomprogrammer.github.io/rust-ascii/ascii/enum.AsciiChar.html). |
| 36 | |
| 37 | ## License |
| 38 | |
| 39 | Licensed under either of |
| 40 | |
| 41 | * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 42 | * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 43 | |
| 44 | at your option. |
| 45 | |
| 46 | ### Contribution |
| 47 | |
| 48 | Unless you explicitly state otherwise, any contribution intentionally |
| 49 | submitted for inclusion in the work by you, as defined in the Apache-2.0 |
| 50 | license, shall be dual licensed as above, without any additional terms or |
| 51 | conditions. |
| 52 | |
| 53 | ## History |
| 54 | |
| 55 | The original purpose of this crate was to provide standins for the then |
| 56 | unstable `encode_utf8()` and `encode_utf16()`. |
| 57 | The standins were removed in 0.3 when Rust 1.15 stabilized the `encode_` |
| 58 | methods, but the other stuff I added, such as iterators like |
| 59 | those `encode_utf{8,16}() returned for a while, might still be of use. |