Skip to main content

define_constant_string

Macro define_constant_string 

Source
macro_rules! define_constant_string {
    {
        $( #[ $($attr:tt)* ] )*
        $name:ident = $string:expr;
    } => { ... };
}
Expand description

Define a ZST struct for a fixed, constant, argument string in a netdoc item

Convenience macro to define a unit struct, derive many traits, and derive ConstantString.

§Example

use tor_netdoc::define_constant_string;
use tor_netdoc::derive_deftly_template_ConstantString; // sadly, needed for Reasons

define_constant_string! {
    /// The shared random algorithm name for the V1 shared random protocol
    ///
    /// This is a constant string, since the version defines the hash algorithm.
    SharedRandV1AlgName = "sha3-256";
}

assert_eq!("sha3-256".parse::<SharedRandV1AlgName>(), Ok(SharedRandV1AlgName));
assert_eq!(SharedRandV1AlgName.to_string(), "sha3-256");

§Input

define_constant_string! {
    #[ATTRIBUTES...]
    TYPE_NAME = STRING_LITERAL;
}

§Generated items

#[ATTRIBUTES...]
pub struct TYPE_NAME;

Implementations of Default, Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash.

Implementations of [FromStr, Display, and NormalItemArgument]. Therefore also ItemArgument and ItemArgumentParseable.