1df783217Sopenharmony_ci# unicode-width
2df783217Sopenharmony_ci
3df783217Sopenharmony_ciDetermine displayed width of `char` and `str` types according to
4df783217Sopenharmony_ci[Unicode Standard Annex #11][UAX11] rules.
5df783217Sopenharmony_ci
6df783217Sopenharmony_ci[UAX11]: http://www.unicode.org/reports/tr11/
7df783217Sopenharmony_ci
8df783217Sopenharmony_ci[![Build Status](https://travis-ci.org/unicode-rs/unicode-width.svg)](https://travis-ci.org/unicode-rs/unicode-width)
9df783217Sopenharmony_ci
10df783217Sopenharmony_ci[Documentation](https://unicode-rs.github.io/unicode-width/unicode_width/index.html)
11df783217Sopenharmony_ci
12df783217Sopenharmony_ci```rust
13df783217Sopenharmony_ciextern crate unicode_width;
14df783217Sopenharmony_ci
15df783217Sopenharmony_ciuse unicode_width::UnicodeWidthStr;
16df783217Sopenharmony_ci
17df783217Sopenharmony_cifn main() {
18df783217Sopenharmony_ci    let teststr = "Hello, world!";
19df783217Sopenharmony_ci    let width = UnicodeWidthStr::width(teststr);
20df783217Sopenharmony_ci    println!("{}", teststr);
21df783217Sopenharmony_ci    println!("The above string is {} columns wide.", width);
22df783217Sopenharmony_ci    let width = teststr.width_cjk();
23df783217Sopenharmony_ci    println!("The above string is {} columns wide (CJK).", width);
24df783217Sopenharmony_ci}
25df783217Sopenharmony_ci```
26df783217Sopenharmony_ci
27df783217Sopenharmony_ci**NOTE:** The computed width values may not match the actual rendered column
28df783217Sopenharmony_ciwidth. For example, the woman scientist emoji comprises of a woman emoji, a
29df783217Sopenharmony_cizero-width joiner and a microscope emoji.
30df783217Sopenharmony_ci
31df783217Sopenharmony_ci```rust
32df783217Sopenharmony_ciextern crate unicode_width;
33df783217Sopenharmony_ciuse unicode_width::UnicodeWidthStr;
34df783217Sopenharmony_ci
35df783217Sopenharmony_cifn main() {
36df783217Sopenharmony_ci    assert_eq!(UnicodeWidthStr::width("�"), 2); // Woman
37df783217Sopenharmony_ci    assert_eq!(UnicodeWidthStr::width("�"), 2); // Microscope
38df783217Sopenharmony_ci    assert_eq!(UnicodeWidthStr::width("�‍�"), 4); // Woman scientist
39df783217Sopenharmony_ci}
40df783217Sopenharmony_ci```
41df783217Sopenharmony_ci
42df783217Sopenharmony_ciSee [Unicode Standard Annex #11][UAX11] for precise details on what is and isn't
43df783217Sopenharmony_cicovered by this crate.
44df783217Sopenharmony_ci
45df783217Sopenharmony_ci## features
46df783217Sopenharmony_ci
47df783217Sopenharmony_ciunicode-width does not depend on libstd, so it can be used in crates
48df783217Sopenharmony_ciwith the `#![no_std]` attribute.
49df783217Sopenharmony_ci
50df783217Sopenharmony_ci## crates.io
51df783217Sopenharmony_ci
52df783217Sopenharmony_ciYou can use this package in your project by adding the following
53df783217Sopenharmony_cito your `Cargo.toml`:
54df783217Sopenharmony_ci
55df783217Sopenharmony_ci```toml
56df783217Sopenharmony_ci[dependencies]
57df783217Sopenharmony_ciunicode-width = "0.1.7"
58df783217Sopenharmony_ci```
59