ranting 0.1.2

Linguistic formatting placeholder extensions for rust
Documentation

Ranting ╰(°Д°)/

This library provides Ranting, a trait for inflection within say!() litteral string placeholders.

[dependencies]
ranting = "0.1"

Details

  • A say!() macro produces a String similar to format!(), but with placeholder markers a pronouns can be received. A verb alongside, always specified in plural, inflects accordingly.
use ranting::*;

fn name(who: Noun) -> String {
    say!("{:who do} say {`who} name is {who}.")
}

# fn main() {
assert_eq!(
    name(Noun::new("Jane", "I")),
    "I do say my name is Jane.".to_string()
);
assert_eq!(
    name(Noun::new("Tarzan", "he")),
    "He does say his name is Tarzan.".to_string()
);
# }
  • Here, Noun has the Ranting trait. You can use #[derive(Ranting)] on a struct or enum fo similar behavior. A struct should also hve a name and a subject String variable. Use I .. they, thou or ye.

  • A placeholder to display a Ranting variable has the structure:

  • With , and ^ lower- and uppercase are enforced, but a placeholder at sentence start is assumed to be uppercase. Also an article or verb with an uppercase enforces using an uppercase.
# use ranting::*;
fn state(who: Noun, liberty: &str) -> String {
    say!("{haven't :who} a {liberty} to say {a who's} land is {~who}?")
}

# fn main() {
assert_eq!(
    state(Noun::new("earl", "he"), "right"),
    "Hasn't he a right to say an earl's land is his?".to_string()
);
assert_eq!(
    state(Noun::new("farmers", "they"), "right"),
    "Haven't they a right to say some farmers' land is theirs?".to_string()
);
# }
  • An article, possesive 's or verbs before the noun are also adapted. Normal variables just follow their Display or Debug traits.

  • With the "inflector" feature, a given Ranting trait can also be inflected to plural or singular.

  • To force plurality use +, for a singular use -. If prependeded by #var, plurality of the noun is adapted to the count of variable var. Which is displayed, unless prepended with a '?'. Other words within the placeholder are adapted as well.

  • A Noun or pronoun is displayed dependent on its leading character or string marker.

    • '?' - subject in inflection, but neither variable nor its space is displayed.
    • : - subject
    • @ - object
    • ` - possesive
    • ~ - adjective
    • '*' - display the name, and mark that this is the Ranting element in the placeholder.
    • '' - similarly, but passes "word" and mutates the Ranting element.
  • If a Noun or plurality is hidden with a leading question mark, its inflection still applies.

  • The article can be one of a, an, some the those or these. These and those are converted to this and that if the pronoun is singular.

  • ack!() and nay!() provide an Ok() / Err() return with a say!() formatted string included. Intended for allow / deny responses, rather than error handling.

Positional argument and numeric references are supported, but not named arguments.