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;