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

Overview

Easy access to struct fields in strings

🐠 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."); 
}

Cascade

🦞 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)]
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

🦞 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!"); 
}

More Information

πŸ¦• Documentation
🦎 Changelog
🐱 GitHub
πŸ‘Ύ Discord Server


License

Licensed under either of Apache 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.
You might also like...
sg = Steam Guard, access sg verification code locally.

Steam Guard CLI Access your Steam Guard token locally. Credit https://github.com/steevp/UpdogFarmer/blob/master/app/src/main/java/com/steevsapps/idled

Gix is a command-line interface (CLI) to access git repositories

gix is a command-line interface (CLI) to access git repositories. It's written to optimize the user-experience, and perform as good or better than the

Learning rust by coding different sorting algorithms in it
Learning rust by coding different sorting algorithms in it

Sorting in Rust Sorting a 32 bit unsigned integer vector by using: Radix Sort Quick Sort Merge Sort Bubble Sort Inbuilt Sort (Probably Tim Sort) This

Like Lua, but in Rust, and different

AirScript It's like Lua, but in Rust, and different. Introduction AirScript is a dynamically typed, interpreted language inspired by Lua and written i

A tool for transposing harmonica tabs into different positions and tunings
A tool for transposing harmonica tabs into different positions and tunings

A tool for transposing harmonica tabs into different positions and tunings

Irx-config - The library provides convenient way to represent/parse configuration from different sources

The irx-config library provides convenient way to represent/parse configuration from different sources. The main goals is to be very easy to use and t

hexyl is a simple hex viewer for the terminal. It uses a colored output to distinguish different categories of bytes
hexyl is a simple hex viewer for the terminal. It uses a colored output to distinguish different categories of bytes

hexyl is a simple hex viewer for the terminal. It uses a colored output to distinguish different categories of bytes (NULL bytes, printable ASCII characters, ASCII whitespace characters, other ASCII characters and non-ASCII).

Helps you keep track of time for team members across different time zones & DST changes

Teamdate Helps you keep track of time for team members across different timezones and other daylight saving changes based off their location. Because

Rust implementation of custom numeric base conversion.

base_custom Use any characters as your own numeric base and convert to and from decimal. This can be taken advantage of in various ways: Mathematics:

Releases(v0.1.3)
Owner
Dekirisu
Dekirisu
zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets you're watching easily into watchlists for easy access on your terminal.

zigfi zigfi is an open-source stocks, commodities and cryptocurrencies price monitoring CLI app, written fully in Rust, where you can organize assets

Aldrin Zigmund Cortez Velasco 17 Sep 8, 2022
A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin"

jordin Finally! A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin". Additionally, this one-of-a-k

jordin 2 Aug 4, 2022
Librarian runs pre-configured commands against a group of files that match a set of filters

Filesystem Librarian Librarian runs pre-configured commands against a group of files that match a set of filters. The group of files is called a libra

Jason Rogena 8 Sep 14, 2022
Parse command line arguments by defining a struct.

StructOpt Parse command line arguments by defining a struct. It combines clap with custom derive. Documentation Find it on Docs.rs. You can also check

Guillaume P. 2.5k Sep 30, 2022
Vari (VΓ€ri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal.

Vari Vari (VΓ€ri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal. Like Rich library for Python. VΓ€ri means "co

azur 12 Mar 12, 2022
Small CLI for escaping and unescaping characters in strings

?? esc Small CLI for escaping characters in strings. Install cargo install esc Usage cat LICENSE-MIT | esc escape | pbcopy pbpaste | esc unescape | pb

Seth 1 Nov 26, 2021
Vim plugin to quickly parse strings into arrays.

butcher Vim plugin to quickly parse strings into arrays. It is painful to write arrays in any programming language, so butcher makes it easy for you.

null 5 Dec 31, 2021
A CLI tool to rename files to randomly generated strings.

rng-rename A CLI tool to rename files to randomly generated strings. Why? Suppose you downloaded a few hundred images to use as your desktop wallpaper

null 2 Feb 24, 2022
A small command-line utility for encoding and decoding bech32 strings

A small command-line utility for encoding and decoding bech32 strings.

Charlie Moog 4 Sep 11, 2022
A Rust synchronisation primitive for "Multiplexed Concurrent Single-Threaded Read" access

exit-left verb; 1. To exit or disappear in a quiet, non-dramatic fashion, making way for more interesting events. 2. (imperative) Leave the scene, and

Jonathan de Jong 0 Dec 5, 2021