Named Tups
Provides a new type called Named Tups that can be called using the tup! macro. Named Tups are structs that can
contain a set of named arguments, effectively they work like normal tuples that can be accessed and created using an
actual name.
The idea of named tuples is to provide a way to quickly iterate on ideas without having to create a builder struct or losing the ability to type check at compile time. Named tuples also allow the creation of default values that can replace nonexistent arguments.
[]
= "0.3.1"
[]
= "0.4.0"
[]
And put the following in your build.rs file.
If you would prefer for this crate to not scan your project files to determine what named arguments are being used add a list of the named tup arguments you used in your Cargo.toml like so.
[]
= ["count", "ingredients", "eggs", "price"]
Examples
use tup;
let count = 5;
// This will have the type of Tup!(count: i32, ingredients: [&str; 3], eggs: bool)
let cakes = tup!;
// We can just add a price afterwards
let mut cakes = cakes + tup!;
// And now it has the type of Tup!(eggs: bool, ingredients: [&str; 3], count: i32, price: i32)
// Once the price is in the tup we can just update it!
cakes.price = 4;
// Will print tup { count: 5, eggs: true, ingredients: ["milk", "flower", "sugar"], price: 4 }
println!;
To use defaults just annotate the item where you set a field
with #[tup_default]. Additionally since the
defaulted tup! is a type you need to convert into it by calling .into_tup() which can be accessed through
the TupInto trait.
use ;
let options = tup!;
// Converts to Tup!(read: false, write: true, create: false, timeout: 5)
open_file;
To test the crate enable the feature dev-test.
Roadmap
- Write some more tests
- Serialise and Deserialise using Serde
- Provide nice looking types for cargo doc