Easy access to struct fields in strings
Cargo.toml
:
[dependencies]
strung = "0.1.3"
use strung::prelude::*;
#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung("{0} is {1}th");
}
#[derive(Strung)]
struct Struct {
name: &'static str,
pos: u32,
}
fn main(){
let s: String = Struct{name:"Bob", pos:10}.strung("{name} is {pos}th.");
}
Prefix and Postix Prefabs
strung()
:
#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
let t = Struct("Bob", 10);
let s = t.strung_curly("{0} is {1}th.");
let s = t.strung_angle("<0> is <1>th.");
let s = t.strung_dollry("${0} is ${1}th.");
let s = t.strung_dollar("$0 is $1th.");
let s = t.strung_hashtag("#0 is #1th.");
}
Custom Prefix and Postix
#[derive(Strung)]
#[strung("<",">")]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung("<0> is <1>th.");
}
#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
strung::config::static_global("<",">");
let s: String = Struct("Bob", 10).strung_static("<0> is <1>th.");
}
#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung_dynamic("<",">","<0> is <1>th.");
}
Cascade
dollar
and hashtag
prefab!
#[cscd]
, #[cascade]
, #[strung(cscd)]
or #[strung(cascade)]
on a field:
#[derive(Strung)]
struct Struct (&'static str, u32);
#[derive(Strung)]
struct Cascade (u32, #[cscd] Struct);
fn main(){
let s: String = Cascade(11,Struct("Bob", 10))
.strung_dollar("$1.0 is $1.1th for the $0th time!");
}
Ignore
#[igno]
, #[strung(igno)]
or #[strung(ignore)]
on a field
#[igno]
:
struct NoDisplay;
#[derive(Strung)]
struct Struct (&'static str, u32, #[igno] NoDisplay);
fn main(){
let s: String = Struct("Bob", 10, NoDisplay)
.strung_dollar("$0 is $1th, he won $2!");
}
More Information
Licensed under either of LicenseApache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.