utf8-rune 0.0.1

Lightweight crate that aims at being a building block for libraries that work with UTF-8 data. This crate provides the struct Rune which can thought of in some cases as a drop-in replacement to Rust's char type. This crate also provides a few low-level tools to work with raw pointers of bytes and work with a sequence of bytes to produce valid UTF-8 data. The idea of Rune both borrows from and expands Golang's notion of rune such that rather than representing one 32 bits integer, each `utf8_rune::Rune` represents a set of bytes that, when displayed together represent a single visible UTF-8 character.
Documentation
  • Coverage
  • 42.11%
    16 out of 38 items documented16 out of 19 items with examples
  • Size
  • Source code size: 119.28 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.72 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • gabrielfalcao

UTF8 Rune

Lightweight crate that aims at being a building block for libraries that work with UTF-8 data.

This crate provides the struct Rune which can thought of in some cases as a drop-in replacement to Rust's char type.

This crate also provides a few low-level tools to work with raw pointers of bytes and work with a sequence of bytes to produce valid UTF-8 data.

The idea of Rune both borrows from and expands Golang's notion of rune such that rather than representing one 32 bits integer, each utf8_rune::Rune represents a set of bytes that, when displayed together represent a single visible UTF-8 character.

Examples

utf8_rune::Rune

use utf8_rune::Rune;
let rune = Rune::new("πŸ‘©πŸ»β€πŸš’");
assert_eq!(rune.len(), 15);
assert_eq!(rune.as_str(), "πŸ‘©πŸ»β€πŸš’");
assert_eq!(rune.as_bytes(), "πŸ‘©πŸ»β€πŸš’".as_bytes());
assert_eq!(rune.as_bytes(), *&rune);

utf8_rune::Runes

use utf8_rune::Runes;
let parts = Runes::new("πŸ‘©πŸ»β€πŸš’πŸ‘ŒπŸΏπŸ§‘πŸ½β€πŸš’πŸ‘¨β€πŸš’πŸŒΆοΈπŸŽΉπŸ’”πŸ”₯❀️‍πŸ”₯β€οΈβ€πŸ©Ή");
assert_eq!(
    parts
        .runes().unwrap_or_default()
        .iter()
        .map(|rune| rune.to_string())
        .collect::<Vec<String>>(),
    vec![
        "πŸ‘©πŸ»β€πŸš’",
        "πŸ‘ŒπŸΏ",
        "πŸ§‘πŸ½β€πŸš’",
        "πŸ‘¨β€πŸš’",
        "🌢️",
        "🎹",
        "πŸ’”",
        "πŸ”₯",
        "❀️‍πŸ”₯",
        "β€οΈβ€πŸ©Ή",
    ]
);