#display #derive #no-alloc #no-std

no-std description

like Display, but 'static

3 releases (breaking)

0.3.0 Nov 2, 2024
0.2.0 Nov 1, 2024
0.1.0 Nov 1, 2024

#2528 in Rust patterns

Download history 323/week @ 2024-10-29 60/week @ 2024-11-05 3/week @ 2024-11-19 2/week @ 2024-12-10

69 downloads per month

MIT license

6KB

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());
}

Dependencies

~215–760KB
~17K SLoC

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy