This library provides Ranting
, a trait for inflection within say!()
litteral string placeholders.
toml
[dependencies]
ranting = "0.1"
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.```rust use ranting::*;
fn name(who: Noun) -> String { say!("{:who do} say {`who} name is {who}.") }
asserteq!( name(Noun::new("Jane", "I")), "I do say my name is Jane.".tostring() ); asserteq!( name(Noun::new("Tarzan", "he")), "He does say his name is Tarzan.".tostring() );
```
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:
{[,^]?(article |verb )?([+-]|#var )?[':@~?*]noun( verb):fmt}
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.
```rust
fn state(who: Noun, liberty: &str) -> String { say!("{haven't :who} a {liberty} to say {a who's} land is {~who}?") }
asserteq!( state(Noun::new("earl", "he"), "right"), "Hasn't he a right to say an earl's land is his?".tostring() ); asserteq!( state(Noun::new("farmers", "they"), "right"), "Haven't they a right to say some farmers' land is theirs?".tostring() );
```
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@
- object`
- possesive~
- adjective"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.