#text-layout #text #unicode-text #rtl #bidi #unicode

no-std unicode-bidi

Implementation of the Unicode Bidirectional Algorithm

31 releases

0.3.18 Dec 16, 2024
0.3.17 Oct 2, 2024
0.3.15 Jan 17, 2024
0.3.14 Dec 6, 2023
0.2.0 Jul 23, 2015

#66 in Encoding

Download history 2590796/week @ 2026-01-07 2632996/week @ 2026-01-14 3085345/week @ 2026-01-21 3134903/week @ 2026-01-28 3365130/week @ 2026-02-04 3198709/week @ 2026-02-11 3435898/week @ 2026-02-18 3649840/week @ 2026-02-25 4557866/week @ 2026-03-04 4268356/week @ 2026-03-11 3739468/week @ 2026-03-18 3708569/week @ 2026-03-25 4058908/week @ 2026-04-01 4398905/week @ 2026-04-08 4524765/week @ 2026-04-15 4978313/week @ 2026-04-22

18,670,365 downloads per month
Used in 11,005 crates (75 directly)

MIT/Apache

250KB
4K SLoC

unicode-bidi

This crate implements the Unicode Bidirectional Algorithm for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release.

Documentation

CI AppVeyor


lib.rs:

This crate implements the Unicode Bidirectional Algorithm for display of mixed right-to-left and left-to-right text. It is written in safe Rust, compatible with the current stable release.

Example

use unicode_bidi::BidiInfo;

// This example text is defined using `concat!` because some browsers
// and text editors have trouble displaying bidi strings.
let text = concat![
  "א",
  "ב",
  "ג",
  "a",
  "b",
  "c",
];

// Resolve embedding levels within the text.  Pass `None` to detect the
// paragraph level automatically.
let bidi_info = BidiInfo::new(&text, None);

// This paragraph has embedding level 1 because its first strong character is RTL.
assert_eq!(bidi_info.paragraphs.len(), 1);
let para = &bidi_info.paragraphs[0];
assert_eq!(para.level.number(), 1);
assert_eq!(para.level.is_rtl(), true);

// Re-ordering is done after wrapping each paragraph into a sequence of
// lines. For this example, I'll just use a single line that spans the
// entire paragraph.
let line = para.range.clone();

let display = bidi_info.reorder_line(para, line);
assert_eq!(display, concat![
  "a",
  "b",
  "c",
  "ג",
  "ב",
  "א",
]);

Features

  • std: Enabled by default, but can be disabled to make unicode_bidi #![no_std] + alloc compatible.
  • hardcoded-data: Enabled by default. Includes hardcoded Unicode bidi data and more convenient APIs.
  • serde: Adds serde::Serialize and serde::Deserialize implementations to relevant types.

Dependencies

~0–730KB
~12K SLoC