encode_unicode/
lib.rs

1/* Copyright 2016-2022 Torbjørn Birch Moltu
2 * Copyright 2018 Aljoscha Meyer
3 *
4 * Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
5 * http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
6 * http://opensource.org/licenses/MIT>, at your option. This file may not be
7 * copied, modified, or distributed except according to those terms.
8 */
9
10
11/*!
12Miscellaneous UTF-8 and UTF-16 types and methods.
13
14# Optional features:
15* `#![no_std]`-mode: There are a few differences:
16  * `Error` doesn't exist, but `description()` is made available as an inherent impl.
17  * `Extend`/`FromIterator`-implementations for `String`/`Vec<u8>`/`Vec<u16>` are missing.
18  * There is no `io`, so `Utf8Iterator` and `Utf8CharSplitter` doesn't implement `Read`.
19
20  This feature is enabled by setting `default-features=false` in `Cargo.toml`:
21  `encode_unicode = {version="0.3.4", default-features=false}`
22* Integration with the [ascii](https://tomprogrammer.github.io/rust-ascii/ascii/index.html) crate:  
23  Convert `Utf8Char` and `Utf16Char` to and from
24  [`ascii::AsciiChar`](https://tomprogrammer.github.io/rust-ascii/ascii/enum.AsciiChar.html).
25
26# Minimum supported Rust version
27
28The minimum supported Rust version for 1.0.\* releases is 1.56.  
29Later 1.y.0 releases might require newer Rust versions, but the three most
30recent stable releases at the time of publishing will always be supported.
31For example this means that if the current stable Rust version is 1.66 when
32`encode_unicode` 1.1.0 is released, then `encode_unicode` 1.1.\* will
33not require a newer Rust version than 1.63.
34
35[crates.io page](https://crates.io/crates/encode_unicode)  
36[github repository](https://github.com/tormol/encode_unicode)
37
38*/
39
40#![cfg_attr(not(feature="std"), no_std)]
41
42#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
43#![allow(
44    clippy::unusual_byte_groupings,// I sometimes group into UTF-8 control part and codepoint part
45    clippy::derive_hash_xor_eq,// tested
46    clippy::len_without_is_empty,// the character types are never empty
47    clippy::needless_return,// `foo.bar();\n foo` looks unfinished
48    clippy::redundant_closure_call,// not redundant in macros
49    clippy::cast_lossless,// the sizes are part of the struct name and so won't change
50    clippy::many_single_char_names,// the variables are in different scopes
51    clippy::cmp_owned,// smaller than pointer, and no allocations anyway
52    clippy::wrong_self_convention,// smaller than pointer
53    clippy::needless_range_loop,// the suggested iterator chains are less intuitive
54    clippy::identity_op,// applying a set of opereations with varying arguments to many elements looks nice
55    clippy::get_first,// .get(0), .get(1) is more readable
56    clippy::question_mark,// I prefer it very explicit
57)]
58#![warn(clippy::doc_markdown, clippy::manual_filter_map)]
59// opt-in lints that might be interesting to recheck once in a while:
60//#![warn(clippy::unwrap_used)]
61
62mod errors;
63mod traits;
64mod utf8_char;
65mod utf8_iterators;
66mod utf16_char;
67mod utf16_iterators;
68mod decoding_iterators;
69
70pub use traits::{CharExt, U8UtfExt, U16UtfExt, StrExt, IterExt, SliceExt};
71pub use utf8_char::Utf8Char;
72pub use utf16_char::Utf16Char;
73
74pub mod error {// keeping the public interface in one file
75    //! Errors returned by various conversion methods in this crate.
76    pub use crate::errors::{FromStrError, EmptyStrError};
77    pub use crate::errors::{CodepointError, NonAsciiError, NonBmpError};
78    pub use crate::errors::{Utf8Error, Utf8ErrorKind};
79    pub use crate::errors::{Utf16SliceError, Utf16ArrayError, Utf16TupleError};
80    pub use crate::errors::{Utf16FirstUnitError, Utf16PairError};
81}
82
83pub mod iterator {
84    //! Iterator types that you should rarely need to name
85    pub use crate::utf8_iterators::{Utf8Iterator, Utf8CharSplitter, Utf8Chars, Utf8CharIndices};
86    pub use crate::utf16_iterators::{Utf16Iterator, Utf16CharSplitter, Utf16Chars, Utf16CharIndices};
87    pub use crate::decoding_iterators::{Utf8CharMerger, Utf8CharDecoder};
88    pub use crate::decoding_iterators::{Utf16CharMerger, Utf16CharDecoder};
89}