non_empty_str/macros.rs
1//! Macros for creating non-empty strings in `const` contexts.
2
3/// Constantly constructs [`Str`] from the given string, failing compilation if the string is empty.
4///
5/// # Examples
6///
7/// Simple usage:
8///
9/// ```
10/// use non_empty_str::const_str;
11///
12/// let nekit = const_str!("nekit");
13/// ```
14///
15/// Compilation failure if the string is empty:
16///
17/// ```compile_fail
18/// use non_empty_str::const_str;
19///
20/// let empty = const_str!("");
21/// ```
22///
23/// [`Str`]: crate::str::Str
24#[macro_export]
25macro_rules! const_str {
26 ($string: expr) => {
27 const { $crate::str::Str::from_str($string).expect($crate::str::EMPTY) }
28 };
29}