1 /* Copyright 2016 The encode_unicode Developers 2 * 3 * Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4 * http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5 * http://opensource.org/licenses/MIT>, at your option. This file may not be 6 * copied, modified, or distributed except according to those terms. 7 */ 8 9 10 /*! 11 Miscellaneous UTF-8 and UTF-16 types and methods. 12 13 # Optional features: 14 * `#![no_std]`-mode: There are a few differences: 15 * `Error` doesn't exist, but `description()` is made available as an inherent impl. 16 * `Extend`/`FromIterator`-implementations for `String`/`Vec<u8>`/`Vec<u16>` are missing. 17 * There is no `io`, so `Utf8Iterator` and `Utf8CharSplitter` doesn't implement `Read`. 18 19 This feature is enabled by setting `default-features=false` in `Cargo.toml`: 20 `encode_unicode = {version="0.3.4", default-features=false}` 21 * Integration with the [ascii](https://tomprogrammer.github.io/rust-ascii/ascii/index.html) crate: 22 Convert `Utf8Char` and `Utf16Char` to and from 23 [ascii::`AsciiChar`](https://tomprogrammer.github.io/rust-ascii/ascii/enum.AsciiChar.html). 24 25 The minimum supported version of Rust is 1.15, 26 older versions might work now but can break with a minor update. 27 28 [crates.io page](https://crates.io/crates/encode_unicode) 29 [github repository](https://github.com/tormol/encode_unicode) 30 31 */ 32 33 #![warn(missing_docs)] 34 35 #![cfg_attr(not(feature="std"), no_std)] 36 // either `cargo clippy` doesn't see theese, or I get a warning when I build. 37 #![cfg_attr(feature="clippy", feature(plugin))] 38 #![cfg_attr(feature="clippy", plugin(clippy))] 39 #![cfg_attr(feature="clippy", allow(derive_hash_xor_eq))]// tested 40 #![cfg_attr(feature="clippy", allow(len_without_is_empty))]// UtfxChar is never empty 41 #![cfg_attr(feature="clippy", allow(match_same_arms))]// looks better IMO 42 #![cfg_attr(feature="clippy", allow(needless_return))]// `foo.bar(); foo` looks unfinished 43 #![cfg_attr(feature="clippy", allow(redundant_closure))]// keep it explicit 44 #![cfg_attr(feature="clippy", allow(redundant_closure_call))]// not redundant in macros 45 #![cfg_attr(feature="clippy", allow(cast_lossless))]// too much noise (and too verbose) 46 // precedence: I prefer spaces to parentheses, but it's nice to recheck. 47 48 mod errors; 49 mod traits; 50 mod utf8_char; 51 mod utf8_iterators; 52 mod utf16_char; 53 mod utf16_iterators; 54 mod decoding_iterators; 55 56 pub use traits::{CharExt, U8UtfExt, U16UtfExt, StrExt, IterExt, SliceExt}; 57 pub use utf8_char::Utf8Char; 58 pub use utf16_char::Utf16Char; 59 pub use utf8_iterators::{Utf8Iterator, iter_bytes}; 60 pub use utf16_iterators::{Utf16Iterator, iter_units}; 61 62 pub mod error {// keeping the public interface in one file 63 //! Errors returned by various conversion methods in this crate. 64 pub use errors::{FromStrError, EmptyStrError}; 65 pub use errors::{InvalidCodepoint, InvalidUtf8}; 66 pub use errors::{InvalidUtf8FirstByte,InvalidUtf16FirstUnit}; 67 pub use errors::{InvalidUtf8Slice,InvalidUtf16Slice}; 68 pub use errors::{InvalidUtf8Array,InvalidUtf16Array,InvalidUtf16Tuple}; 69 pub use errors::Utf16PairError; 70 } 71 72 pub mod iterator { 73 //! Iterator types that you should rarely need to name 74 pub use utf8_iterators::{Utf8Iterator, Utf8CharSplitter, Utf8Chars, Utf8CharIndices}; 75 pub use utf16_iterators::{Utf16Iterator, Utf16CharSplitter, Utf16Chars, Utf16CharIndices}; 76 pub use decoding_iterators::{Utf8CharMerger, Utf8CharDecoder}; 77 pub use decoding_iterators::{Utf16CharMerger, Utf16CharDecoder}; 78 } 79