TAAFT
Free mode
100% free
Freemium
Free Trial
Deals

AntString (An annotated string)

togglebyte / antstring

An annotated string type in Rust, made up of string slices

2 0 Language: Rust License: MIT Updated: 8mo ago

README

AntString (An annotated string)

A string type made up of multiple annotated string slices.

use antstring::{AntString, CharAnnotation, Contains, Find};

#[derive(Debug)]
enum Color {
    Red,
    Green,
    Blue,
}

impl CharAnnotation for Color {
    type Annotation = Self;

    fn annotate(&self) -> &Self::Annotation {
        self
    }
}

let input = [(&Color::Red, "012"), (&Color::Green, "34"), (&Color::Blue, "5")];
let string = AntString::with_annotations(&input);

assert!(string.contains('3'));
assert_eq!(string.find('3').unwrap(), 3);

for (color, c) in string.annotated_chars() {
    eprintln!("{c} [{color:?}]");
}

Thanks to anned20 for the name

0 AIs selected
Clear selection
#
Name
Task