Ranting ╰(°Д°)/

github crates.io docs.rs

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

toml [dependencies] ranting = "0.2"


Details

```rust use ranting::; use ranting_derive::;

fn say_this(who: Noun, title: &Noun) -> String { say!("{=who do} say {`who title are} {who}.") }

fn main() { let title = Noun::new("name", "it"); asserteq!( saythis(Noun::new("Jane", "I"), &title), "I do say my name is Jane.".tostring() ); asserteq!( saythis(Noun::new("Tarzan", "he"), &title), "He does say his name is Tarzan.".tostring() ); } ```

```rust fn state(who: T, liberty: &str) -> String { say!("{haven't =who} a {liberty} to say {a who's} land is {~who}?") }

[derive_ranting]

[ranting(subject = "he")]

struct Earl {}

[derive_ranting]

[ranting(subject = "they")]

struct Farmers {}

fn main() { asserteq!( state(Earl {}, "right"), "Hasn't he a right to say an earl's land is his?".tostring() ); asserteq!( state(Farmers {}, "right"), "Haven't they a right to say some farmers' land is theirs?".tostring() ); } ```

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());

} ```