type_at

Crates.iotype_at
lib.rstype_at
version0.1.0
sourcesrc
created_at2021-10-08 09:43:55.282538
updated_at2021-10-08 09:43:55.282538
descriptionUtility trait to index type of Rust tuples.
homepage
repositoryhttps://github.com/robbepop/type_at
max_upload_size
id462266
size18,654
Robin Freyler (Robbepop)

documentation

https://docs.rs/type_at

README

Type Indexing into Rust Tuples

Provides a trait TypeAt which allow to query the n-th type of a Rust tuple at compile time.

Example: Simple

use type_at::TypeAt;

let _: i8  = <(i8, i16, i32, i64) as TypeAt<0>>::Type::default();
let _: i16 = <(i8, i16, i32, i64) as TypeAt<1>>::Type::default();
let _: i32 = <(i8, i16, i32, i64) as TypeAt<2>>::Type::default();
let _: i64 = <(i8, i16, i32, i64) as TypeAt<3>>::Type::default();

Example: Nested

use type_at::TypeAt;

let _: i64 = <<<<(i8, (i16, (i32, (i64,))))
    as TypeAt<1>>::Type // (i16, (i32, (i64,)))
    as TypeAt<1>>::Type // (i32, (i64,))
    as TypeAt<1>>::Type // (i64,)
    as TypeAt<0>>::Type::default();

Example: Derive

#[derive(TypeAt)]
pub struct TupleStruct(i8, i16, i32);

let _: i8   = <TupleStruct as TypeAt<0>>::Type::default();
let _: i16  = <TupleStruct as TypeAt<1>>::Type::default();
let _: i32  = <TupleStruct as TypeAt<2>>::Type::default();
#[derive(TypeAt)]
pub struct Struct { a: i8, b: i16, c: i32 }

let _: i8   = <Struct as TypeAt<0>>::Type::default();
let _: i16  = <Struct as TypeAt<1>>::Type::default();
let _: i32  = <Struct as TypeAt<2>>::Type::default();

License

Licensed under either of

at your option.

Dual licence: ![badge][license-mit-badge] ![badge][license-apache-badge]

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

Commit count: 23

cargo fmt