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...
βš™οΈ Pre-commit hook for downgrading Python logger syntax

printf-log-formatter Automatically convert f-strings and str.format() syntax to printf-style strings. In other words, this syntax logger.error(f"{1}")

Convert a unix timestamp (seconds) to a struct {year, month, day, hour, minute, second, weekday}.

uts2ts uts2ts is a simple function that does only one thing: It converts a unix timestamp to something slightly more useful. ;-) So why then? Well, it

rehype plugin to use tree-sitter to highlight code in pre code blocks

rehype-tree-sitter rehype plugin to use tree-sitter to highlight code in precode blocks Contents What is this? When should I use this? Install Use

Low level access to processors using the AArch64 execution state.

aarch64-cpu Low level access to processors using the AArch64 execution state. Usage Please note that for using this crate's register definitions (as p

Vari (VΓ€ri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal.
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

Immutable strings, in Rust.
Immutable strings, in Rust.

Immutable Strings Inspired by the bytes crate, which offers zero-copy byte slices, this crate does the same but for strings. It is backed by standard

Rust parser/validator for Debian version strings

debian version handling in rust This simple crate provides a struct for parsing, validating, manipulating and comparing Debian version strings. It aim

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

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.

Releases(v0.1.3)
Owner
Dekirisu
Dekirisu
Statically verified Rust struct field names as strings.

field Statically verified struct field names as strings. See the documentation for more details. Installation Add the following to your Cargo manifest

Indraneel Mahendrakumar 3 Jul 9, 2023
Bit fields and masks for rust!

ubits Bit fields and masks for rust! Provides a macro for generating bit field types complete with flags and some helpful trait implementations. Suppo

Adam Romano 2 Sep 16, 2022
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 18 Oct 24, 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
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.6k Jan 5, 2023
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 10 Dec 25, 2022
🧰 Download pre-built binaries of all your favourite tools with a single command

tool-sync tool-sync is a CLI tool that solves one problem: ?? Download pre-built binaries of all your favourite tools with a single command. tool-sync

Dmitrii Kovanikov 50 Jan 1, 2023
(Pre-Release Software) Secure, Encrypted, P2P chat written atop Warp, IPFS, LibP2P, Dioxus and many more awesome projects and protocols.

Uplink Privacy First, Modular, P2P messaging client built atop Warp. Uplink is written in pure Rust with a UI in Dioxus (which is also written in Rust

Satellite 13 Jan 25, 2023
A crate providing a MemoryCell struct, which stores a current and previous value.

memcell What is a MemoryCell? A MemoryCell is a struct containing both a current and optional previous value. Definition #[derive(Debug, Clone)] pub s

Imajin 9 Nov 21, 2022
Pre-commit hook to help me stop naming files *.yml half of the time

Disallow file endings Pre-commit hook that lets you specify banned file endings. I keep naming half my yaml files *.yaml and the other *.yml and it's

Sondre LillebΓΈ Gundersen 4 Mar 8, 2023