Features
ð convert a struct into a tuple and back ðĶ convert an enum into a tuple and back ðĶĒ get a tuple of (mut) references of fields of a struct ð get a tuple of (mut) references of fields of an enum ðĶĨ ignore specific fields ðĶ do it all recursively
Usage
ð add intuple to the dependencies in the Cargo.toml:
[]
= "0.2"
ðĶ use/import everything into rust:
use *;
ðĶ multiple ways to convert:
Tuple Type
ðĶ access the resulting tuple types through a qualified path:
Ignoring
ðĶĨ ignore specific fields with #[igno]/#[ignore]
ðŧ or #[intuple(igno)]/#[intuple(ignore)]
ðž ignored fields need to implement Default while converting to a struct
Recursion
ðĶ convert recursively with #[recursive]/#[rcsv]
ðĶ or #[intuple(rcsv)]/#[intuple(recursive)]
ðž recursive fields need to derive Intuple
ðĶ recursion also works with .as_tuple_ref() and as_tuple_ref_mut()
Enums
ð converting enums to tuples isn't as straight forward as structs, therefore two methods are implemented!
ð 1. Positional
ð using Intuple - no additional enums or structs are generated
ðĒ field tuples are wrapped in an Option<>, which are inside another tuple
ðĶ the outer tuple has as many fields as there are enum variants
ð the required None variant will convert to (None,None,None,...)
ð any other variant will occupy a slot, depending on its position (None,Some(tuple),None,...)
// Positional
// enums require a 'None' variant
ðĶ 2. Generated Tuple Enums
ð using IntupleEnum - three additional enums will be generated:
ð {EnumName}Intuple, {EnumName}IntupleRef and {EnumName}IntupleRefMut
ðĶ each of those will use the original variant names and contain a tuple
ð to set derives for them, use #[intuple(derive(...))]
â to use them recursivly ANYWHERE, use #[recursive_enum] or #[rcsve]
ðĶĒ .into()/.from(..) are implemented, but the custom methods change to:
ð .from_tuple_enum(..), .into_tuple_enum(), .as_tuple_enum_ref() and .as_tuple_enum_ref_mut()
// Generated
Example: Serde - Thinking out of the box
ðĶ You could use serde without implementing Serialize/Deserialize
ð This only works with the positional enum tuples!
use *;
More Information
ðĶ Changelog ðą GitHub ðū Discord Server