Ranting ╰(°Д°)/
This library provides Ranting, a trait for inflection within say!() litteral string placeholders.
[]
= "0.2"
Details
- A
say!()macro produces a String similar toformat!(), but with placeholder markers a pronouns can be received. A verb alongside, always specified in plural, inflects accordingly.
use *;
use *;
-
Nounis a struct with theRantingtrait. You can use#[derive(Ranting)]on a struct or enum for similar behavior. To specify the subject use I .. they, thou or ye. -
A placeholder to display a Ranting variable has a structure like:
- With
,and^lower- and uppercase are enforced, but a placeholder at sentence start is uppercase by default. Also an article or verb with an uppercase causess an uppercase for the first character.
-
An article, possesive
'sor verbs before the noun are also adapted. Normal placeholders just follow their Display or Debug traits withinsay!(). -
A given Ranting Enum or Struct can also be inflected to plural or singular. To force plurality use
+, for a singular use-. If prependeded by$varor#var, plurality of the noun is adapted to the numeric variable var. Which is displayed, unless prepended with a '?'. The number is converted to a word for#var. Other words within the placeholder are adapted accordingly 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 (as is the default) but also mark this word as the Ranting element in the placeholder. "A {*can can} contain water." (removed the mutname variant)
-
If a Noun or numeric plurality has a leading question mark, it is hidden but its inferred inflection does apply.
-
An 'article' can be one of
a,an,some,the,thoseorthese. These and those are converted to this and that if the pronoun is singular. A question mark indicates its display dependends (see no_article). -
ack!()andnay!()provide an Ok() / Err() return with asay!()formatted string included. Intended for allow or deny ranting responses. Not for error handling, because true errors should be easy to search in code. -
A struct can receive via attributes:
- subject ["it"] - indicates the pronoun, if "$", the struct is assumed to contain a String 'subject'
- name [Struct or Enum name; lowercase] - the display name. when "$' the struct contains a name String.
- singular_end [""] - for inflection, what name + singular_end if the plurality is '-'? can also be "$"
- plural_end ["s"] - likewise, name end if plurality is '+' or #var != 1.
- is_plural [as subject] - if subject is "you", this indicates whether that means plural or not.
- uc [false] - indicate if the word should always start with an uppercase.
- no_article [false] - indicate that the word should be without article if the article if prepended with a '?'. say!("{?the 0} was great!", activity) // e.g. for activity = tennis with no_article=true. (The latter two do not yet have the "$" variant)
Positional argument and numeric references are supported, but named arguments or empty arguments are not, currecntly.
fn main() {
let thing = Noun::new("thing", "it");
assert_eq!(say!("this is {=thing}."), "this is it.".to_string());
assert_eq!(say!("this is {=0}.", thing), "this is it.".to_string());
// won't work:
//assert_eq!("{}", say!("this is {=x}.", x = thing), "this is it.".to_string());
//assert_eq!("{}", say!("this is {=}.", thing), "this is it.".to_string());
}