1 个不稳定版本
0.1.0 | 2021 年 10 月 8 日 |
---|
#82 in #indexing
用于 type_at
7KB
111 行
Rust 元组索引类型
提供了一个允许在编译时查询 Rust 元组第 n 个类型的 trait TypeAt
。
示例:简单
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-apache-badge]
贡献
除非您明确表示,否则根据 Apache-2.0 许可证定义,您提交的任何有意包含在工作中的贡献,将按以下方式双许可,不附加任何其他条款或条件。
依赖项
~3.5MB
~75K SLoC