Skip to content

Instantly share code, notes, and snippets.

@martinmroz
Last active October 27, 2019 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinmroz/79fed5be8b8d4e0cb968a798afd6fff6 to your computer and use it in GitHub Desktop.
Save martinmroz/79fed5be8b8d4e0cb968a798afd6fff6 to your computer and use it in GitHub Desktop.
Mapping a single character onto a Flux Monoid
impl From<u8> for Flux {
fn from(other: u8) -> Self {
if other.is_ascii_whitespace() {
// A line-feed is considered an ASCII whitespace character by `is_ascii_whitespace`.
let lines = if other == ('\n' as u8) { 1 } else { 0 };
Flux::new(CharType::IsSpace, 0, lines, CharType::IsSpace)
} else {
Flux::new(CharType::NotSpace, 1, 0, CharType::NotSpace)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment