mcut 0.1.1

Zero-copy, low-memory multilingual word segmenter using pointwise linear classification and minimal FST
Documentation
/// Token category.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum TokenKind {
  /// Letters, Hangul, Han, kana and other word characters.
  Word,
  /// A run of numeric characters.
  Number,
  /// Whitespace.
  Space,
  /// Punctuation or symbols.
  Punct,
}

/// A borrowed token plus its byte range in the original text.
///
/// `start` and `end` are always UTF-8 character boundaries. In
/// [`crate::CutMode::Full`] and [`crate::CutMode::Search`] tokens may overlap.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Token<'a> {
  /// Token text.
  pub text: &'a str,
  /// Inclusive byte start.
  pub start: usize,
  /// Exclusive byte end.
  pub end: usize,
  /// Token category.
  pub kind: TokenKind,
}

impl<'a> Token<'a> {
  /// Creates a token from a range of `source`.
  ///
  /// The range must be valid UTF-8 boundaries.
  pub fn new(source: &'a str, start: usize, end: usize, kind: TokenKind) -> Self {
    Self {
      text: &source[start..end],
      start,
      end,
      kind,
    }
  }

  /// Creates a word token.
  pub fn word(source: &'a str, start: usize, end: usize) -> Self {
    Self::new(source, start, end, TokenKind::Word)
  }

  /// Creates a number token.
  pub fn number(source: &'a str, start: usize, end: usize) -> Self {
    Self::new(source, start, end, TokenKind::Number)
  }
}