Fork channel

Create a new channel as a copy of main.

Rename channel

Rename main to:

Delete channel

Delete main? This cannot be undone.

lib.rs
use std::collections::{HashMap, HashSet};
use unicode_segmentation::UnicodeSegmentation;

fn checksum(word: &str) -> u8 {
	word.bytes()
		.fold(0, |accumulator, byte| accumulator.overflowing_add(byte).0)
}

fn grapheme_histogram(word: &str) -> HashMap<&str, usize> {
	word.graphemes(true).fold(
		HashMap::with_capacity(word.len()),
		|mut hashmap, grapheme| {
			*hashmap.entry(grapheme).or_insert(0) += 1;
			hashmap
		},
	)
}

pub fn anagrams_for<'a>(word: &str, possible_anagrams: &[&'a str]) -> HashSet<&'a str> {
	let word_lowercased = word.to_lowercase();
	let (word_checksum, word_histogram) = (
		checksum(&word_lowercased),
		grapheme_histogram(&word_lowercased),
	);
	possible_anagrams
		.iter()
		.filter(|possible_anagram| {
			word.len() == possible_anagram.len() && {
				let possible_anagram = possible_anagram.to_lowercase();
				word_lowercased != possible_anagram
					&& word_checksum == checksum(&possible_anagram)
					&& word_histogram == grapheme_histogram(&possible_anagram)
			}
		})
		.copied()
		.collect()
}