Cotton code
44 lines · 1.9 KB · RustRaw
//! WHAT A SURFACE ADMITS (owner, 3 Nov 2026: "I also want to include having//! numbers"): the ink reads a letter or a digit, and the deck it is written on//! decides which it takes, by the columns it narrows by — its title, its//! slip's figure (an amount, a count) and its search columns//! (`rules::ink_match::columns`) — and what each column's type can hold (the//! alphabet's `admits`: a text column letters, an amount or a number digits,//! a web address both). A deck of names takes letters only, so a 0 written//! on People is its o; a deck of amounts digits only, so an o there is its//! 0; Money, its description and its amount together, both. A record pick//! reads by its table's title alone.use crate::definitions::{Column, TableDefinition};use crate::rules::ink_match;use super::{Admits, Alphabet};/// What `definition`'s deck admits: what its title, its slip's figure and/// its search columns hold together.pub fn deck(definition: &TableDefinition, alphabet: &Alphabet) -> Admits {    ink_match::columns(definition)        .iter()        .filter_map(|key| definition.column(key))        .fold(Admits::default(), |held, column| held.union(holds(column, alphabet)))}/// What a record pick of `definition`'s rows admits: they are narrowed by/// their names, so what its title column holds.pub fn pick(definition: &TableDefinition, alphabet: &Alphabet) -> Admits {    definition        .column(&definition.title)        .filter(|column| column.secret != Some(true))        .map(|column| holds(column, alphabet))        .unwrap_or_default()}/// What `column`'s type can hold.fn holds(column: &Column, alphabet: &Alphabet) -> Admits {    let name = serde_json::to_value(column.column_type).ok().and_then(|value| value.as_str().map(str::to_string)).unwrap_or_default();    alphabet.admits(&name)}#[cfg(test)]#[path = "admits_tests.rs"]mod admits_tests;