#display #derive #traits

无std display_derive

派生 Display

1 个不稳定版本

使用旧版Rust 2015

0.0.0 2018年2月1日

482#display

Download history 118/week @ 2024-04-01 54/week @ 2024-04-08 70/week @ 2024-04-15 73/week @ 2024-04-22 86/week @ 2024-04-29 71/week @ 2024-05-06 73/week @ 2024-05-13 67/week @ 2024-05-20 59/week @ 2024-05-27 63/week @ 2024-06-03 45/week @ 2024-06-10 71/week @ 2024-06-17 62/week @ 2024-06-24 34/week @ 2024-07-08 80/week @ 2024-07-15

183 每月下载量
7 个crate(4个直接使用) 中使用

MIT/Apache

6KB
87

派生 Display

Display 特性提供派生。

#[macro_use] extern crate display_derive;

#[derive(Display)]
#[display(fmt = "Error code: {}", code)]
struct RecordError {
    code: u32,
}

#[derive(Display)]
enum EnumError {
    #[display(fmt = "Error code: {}", code)]
    StructVariant {
        code: i32,
    },
    #[display(fmt = "Error: {}", _0)]
    TupleVariant(&'static str),
    #[display(fmt = "An error has occurred.")]
    UnitVariant,
}

依赖项

~2MB
~42K SLoC