1 个不稳定版本
0.1.0 | 2021 年 10 月 8 日 |
---|
#2735 in Rust 模式
7KB
Rust 元组类型索引
提供了一个特性 TypeAt
,允许在编译时查询 Rust 元组的第 n 个类型。
示例:简单
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();
示例:嵌套
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();
示例:派生
#[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();
许可协议
许可协议为以下之一
- Apache 许可证,版本 2.0,(LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
由您选择。
双许可:[![徽章][license-mit-badge]][license-mit-badge] ![徽章][license-apache-badge] ![徽章][license-apache-badge]
贡献
除非您明确声明,否则任何有意提交以包含在作品中的贡献,根据 Apache-2.0 许可证定义,将按以下方式双许可,没有任何额外的条款或条件。
依赖关系
~3.5MB
~74K SLoC