runefix_core/lib.rs
1//! # runefix-core
2//!
3//! Unicode-aware display width engine for terminals, TUI, and Markdown rendering.
4//!
5//! `runefix-core` provides precise width computation for multilingual text,
6//! with support for:
7//!
8//! - East Asian fullwidth characters (CJK)
9//! - Emoji (including multi-codepoint ZWJ sequences)
10//! - Fullwidth punctuation and symbol variants
11//! - Grapheme-aware string truncation and wrapping
12//!
13//! It ensures consistent text alignment across platforms and fonts
14//! by working at the grapheme cluster level, consulting curated Unicode-derived datasets.
15//!
16//! ## Features
17//!
18//! 𧬠**Atom API**
19//! - [`atoms`] β Runefix-specific visual segmentation for layout (width-based units)
20//!
21//! π§© **Segmentation API**
22//! - [`graphemes`] β Unicode-compliant grapheme cluster splitting (UAX #29)
23//!
24//! π **Measurement API**
25//! - [`display_width`] β Total width of a string (grapheme-aware, terminal-style)
26//! - [`display_widths`] β Widths of each grapheme cluster (`Vec<usize>`)
27//! - [`grapheme_widths`] β Widths with original clusters (`Vec<(&str, usize)>`)
28//!
29//! π **Layout API**
30//! - [`truncate_by_width`] β Truncates text by width without splitting graphemes
31//! - [`split_by_width`] β Wraps a string into lines based on terminal width
32//!
33//! π **Ergonomic Extensions**
34//! - [`RuneDisplayWidth`] β Trait for:
35//! - `.rune_width()` on `char`
36//! - `.width()`, `.display_width()`, `.display_widths()` on `str`
37//!
38//! ## Example
39//!
40//! ```rust
41//! use runefix_core::{RuneDisplayWidth, grapheme_widths};
42//!
43//! assert_eq!('δ½ '.rune_width(), 2);
44//! assert_eq!(
45//! grapheme_widths("HiοΌδΈη"),
46//! vec![("H", 1), ("i", 1), ("οΌ", 2), ("δΈ", 2), ("η", 2)]
47//! );
48//! ```
49//!
50//! ## Resources
51//!
52//! - [π Dataset source & CLI](https://github.com/pokeyaro/runefix-rs/tree/main/crates/core)
53//! - [π¦ Crates.io](https://crates.io/crates/runefix-core)
54//! - [π§ͺ docs.rs Documentation](https://docs.rs/runefix-core)
55//!
56//! > **Note:** Enable the `policy` feature to use configurable width strategies
57//! > such as `terminal()`, `markdown()`, or `compact()`.
58
59// βββββ Public APIs βββββββββββββββββββββββββββββββββββββββββββββ
60
61// Atom-based segmentation for layout units (runefix-specific)
62pub use atom::atoms;
63
64// Grapheme-based core processing functions (always available)
65pub use grapheme::{
66 display_width, display_widths, grapheme_widths, graphemes, split_by_width, truncate_by_width,
67};
68
69// Unicode-aware trait extensions for `char` and `str`
70pub use ext::RuneDisplayWidth;
71
72// Unicode data version used internally
73pub use consts::UNICODE_VERSION;
74
75// βββββ Optional: Feature-gated APIs (requires `policy`) βββββββββ
76
77// Configurable width strategy struct
78#[cfg(feature = "policy")]
79pub use policy::WidthPolicy;
80
81// Ergonomic wrapper for applying a WidthPolicy to strings
82#[cfg(feature = "policy")]
83pub use with_policy::WithPolicy;
84
85// Policy-aware versions of grapheme layout functions
86#[cfg(feature = "policy")]
87pub use crate::grapheme::policy_ext::{
88 display_width_with_policy, display_widths_with_policy, grapheme_widths_with_policy,
89 split_by_width_with_policy, truncate_by_width_with_policy,
90};
91
92// βββββ Internal Modules (implementation details) βββββββββββββββ
93
94mod atom;
95mod consts;
96mod ext;
97mod grapheme;
98mod rules;
99mod width;
100
101#[cfg(feature = "policy")]
102mod policy;
103#[cfg(feature = "policy")]
104mod with_policy;