## strung

Easy access of struct fields in strings using different/custom pre/postfix: "Hello, {field}"

### 4 releases

 0.1.3 Sep 19, 2022 Sep 14, 2022 Sep 12, 2022 Sep 12, 2022

#45 in Value formatting

Used in 2 crates (via querio)

MIT/Apache

20KB
62 lines 🐠 add strung to the dependencies in the `Cargo.toml`:

``````[dependencies]
strung = "0.1.3"
``````

🦀 use/import everything of the prelude in rust:

``````use strung::prelude::*;
``````

🦊 works for unnamed fields:

``````#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung("{0} is {1}th");
}
``````

🦊 works for named fields:

``````#[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

🐎 prefabs are most performant - equal to `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

🐎 per struct - performance equal to prefabs:

``````#[derive(Strung)]
#[strung("<",">")]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung("<0> is <1>th.");
}
``````

🦅 global - easiest, a bit less performant:

``````#[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.");
}
``````

🐍 per call - most flexible:

``````#[derive(Strung)]
struct Struct (&'static str, u32);
fn main(){
let s: String = Struct("Bob", 10).strung_dynamic("<",">","<0> is <1>th.");
}
``````

🦞 currently only for `dollar` and `hashtag` prefab!
🐳 use `#[cscd]`, `#[cascade]`, `#[strung(cscd)]` or `#[strung(cascade)]` on a field:

``````#[derive(Strung)]
struct Struct (&'static str, u32);
#[derive(Strung)]
fn main(){
let s: String = Cascade(11,Struct("Bob", 10))
.strung_dollar("\$1.0 is \$1.1th for the \$0th time!");
}
``````

## Ignore

🦞 if a field type doesn't implement Display, it has to be ignored!
🐎 can also be used to gain minimal amounts of performance!
🐳 use `#[igno]`, `#[strung(igno)]` or `#[strung(ignore)]` on a field
🙉 this example wouldn't compile without `#[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!");
}
``````
{"ft_lang_label":"__label__en","ft_lang_prob":0.5869964,"math_prob":0.94472486,"size":2900,"snap":"2023-14-2023-23","text_gpt3_token_len":944,"char_repetition_ratio":0.15711325,"word_repetition_ratio":0.109004736,"special_character_ratio":0.35689655,"punctuation_ratio":0.23063973,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9811044,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-31T03:21:31Z\",\"WARC-Record-ID\":\"<urn:uuid:b0d7f97b-13de-40fe-ad29-ef83791eba68>\",\"Content-Length\":\"39313\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9a76d3b5-18d4-4e77-be29-d3318e6f7b64>\",\"WARC-Concurrent-To\":\"<urn:uuid:515cf317-b0be-473a-a841-1c5e059ef48f>\",\"WARC-IP-Address\":\"104.21.91.94\",\"WARC-Target-URI\":\"https://lib.rs/crates/strung\",\"WARC-Payload-Digest\":\"sha1:ZKZLCCODTY2LJ4SC4GKCHSMNUSCJ6ZC3\",\"WARC-Block-Digest\":\"sha1:T2P3MFBRDZQ23KXTAMOVRZX7RXQ3BQED\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296949533.16_warc_CC-MAIN-20230331020535-20230331050535-00711.warc.gz\"}"}