pub trait Ranting: Display {
// Required methods
fn name(&self, uc: bool) -> String;
fn subjective(&self) -> &str;
fn is_plural(&self) -> bool;
fn inflect(&self, to_plural: bool, uc: bool) -> String;
fn skip_article(&self) -> bool;
}Expand description
The trait required for a struct or enum to function as a noun in a placeholder, derived with #[derive_ranting].
Functions are used in say!() placeholders replacements.
§Examples
#[derive_ranting]
#[ranting(subject = "you", plural_you = true)]
struct OpponentTeam {}
#[derive_ranting]
#[ranting(subject = "he")]
struct ChessPlayer {}
fn big_words_to<T: Ranting>(who: T) -> String {
say!("I will grant {@0} {`0} fight, but {=0 are} going to lose today.", who)
}
let team = OpponentTeam {};
assert_eq!(big_words_to(team),
"I will grant you your fight, but you are going to lose today.");
let magnus = ChessPlayer {};
assert_eq!(big_words_to(magnus),
"I will grant him his fight, but he is going to lose today.");Required Methods§
Sourcefn name(&self, uc: bool) -> String
fn name(&self, uc: bool) -> String
return the name, which is struct name or the #{ranting(name = "..")] value, or self.name
if the name attribute was set to “$”
Sourcefn subjective(&self) -> &str
fn subjective(&self) -> &str
return the subject: “it” or the #{ranting(subject = "..")] value; self.subject if “$”.
Sourcefn is_plural(&self) -> bool
fn is_plural(&self) -> bool
return if plural (the subject, or if you, the #{ranting(plural_you = "true/false")] value,
default false
Sourcefn inflect(&self, to_plural: bool, uc: bool) -> String
fn inflect(&self, to_plural: bool, uc: bool) -> String
return the singular or plural form as configured, starting with capital if uc is set.
use #{ranting(singular_end = "..", plural_end = "..")] if not plural = singular + “s”
Sourcefn skip_article(&self) -> bool
fn skip_article(&self) -> bool
If an article is only required when emphasizing, set #{ranting(no_article = "true")],
and this function will return accordingly (used by placeholders).