Skip to content

Rust crate to get the arity (number of elements) of tuple types with 0-12 elements

License

Notifications You must be signed in to change notification settings

TheBerkin/tuple-arity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tuple-arity

Crates.io Crates.io Docs.rs shield

A simple crate for getting the arity (number of elements) of tuple types with 0 to 12 elements.

How to use

You can use the tuple_arity() function to get the arity of an existing tuple value.

use tuple_arity::*;
assert_eq!(0, tuple_arity(&()));
assert_eq!(1, tuple_arity(&("foo",)));
assert_eq!(2, tuple_arity(&("foo", "bar")));
assert_eq!(3, tuple_arity(&("foo", "bar", "baz")));

You can also use the Arity trait to get the arity of a tuple type directly:

use tuple_arity::Arity;

assert_eq!(0, <()>::ARITY);
assert_eq!(1, <(u8,)>::ARITY);
assert_eq!(2, <(u8, u8)>::ARITY);
assert_eq!(3, <(u8, u8, u8)>::ARITY);
assert_eq!(4, <(u8, u8, u8, u8)>::ARITY);

About

Rust crate to get the arity (number of elements) of tuple types with 0-12 elements

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages