description

Crates.iodescription
lib.rsdescription
version0.3.0
sourcesrc
created_at2024-11-01 13:36:06.488132
updated_at2024-11-02 13:22:14.874213
descriptionlike Display, but 'static
homepage
repositoryhttps://github.com/adryzz/description
max_upload_size
id1431785
size9,531
Lena (adryzz)

documentation

https://docs.rs/description

README

derive(Description)

This library provides a trait and derive macro that is like std::fmt::Display, but using compile-time strings.

The library is fully no_std and no_alloc, and is meant to provide user-facing text for enum-like status messages without code bloat.

[dependencies]
description = "0.3.0"

Example

use description::Description;

#[derive(Description)]
enum ChargerStatus {
    #[description("Charger connected!")]
    Connected,

    #[description("Charger disconnected!")]
    Disconnected,
}

fn main() {
    let charger = ChargerStatus::Connected;

    println!("Charger notification: {}", charger.description());
}

std::fmt::format!()-like compile time formatting is also supported, thanks to const_format

use description::Description;

const SOME_CONSTANT: usize = 5;

#[derive(Description)]
enum SomeStatusEnum {
    #[description("the constant is {SOME_CONSTANT}, and the max u32 is {}", u32::MAX)]
    ShowConstant,

    #[description("i'm not showing the constant")]
    DontShowConstant,
}

fn main() {
    let charger = SomeStatusEnum::ShowConstant;

    println!("enum message: {}", charger.description());
}
Commit count: 9

cargo fmt