devela/code/util/
paste.rs

1// devela::code::util::paste
2//
3
4/// <span class="stab portability" title="re-exported from the `paste` crate">`paste`</span>
5/// Allows to paste identifiers together.
6///
7#[doc = "*Reexported from the [`paste`](https://docs.rs/paste)* crate.\n\n---"]
8///
9/// Within the `paste!` macro, identifiers inside `[<`...`>]` are pasted
10/// together to form a single identifier.
11///
12/// # Examples
13/// ```
14/// # use devela::paste;
15/// paste! {
16///     // Defines a const called `QRST`.
17///     const [<Q R S T>]: &str = "success!";
18/// }
19///
20/// fn main() {
21///     assert_eq!(
22///         paste! { [<Q R S T>].len() },
23///         8,
24///     );
25/// }
26/// ```
27///
28/// ## Case conversion
29///
30/// Use `$var:lower` or `$var:upper` in the segment list to convert an
31/// interpolated segment to lower- or uppercase as part of the paste. For
32/// example, `[<ld_ $reg:lower _expr>]` would paste to `ld_bc_expr` if invoked
33/// with `$reg=Bc`.
34///
35/// Use `$var:snake` to convert CamelCase input to snake\_case.
36/// Use `$var:camel` to convert snake\_case to CamelCase. These compose,
37/// so for example `$var:snake:upper` would give you SCREAMING\_CASE.
38///
39/// The precise Unicode conversions are as defined by [`str::to_lowercase`][0]
40/// and [`str::to_uppercase`][1].
41///
42/// [0]: https://doc.rust-lang.org/core/primitive.str.html#method.to_lowercase
43/// [1]: https://doc.rust-lang.org/core/primitive.str.html#method.to_uppercase
44///
45/// ## Pasting documentation strings
46///
47/// Within the `paste!` macro, arguments to a `#[doc ...]` attribute are
48/// implicitly concatenated together to form a coherent documentation string.
49///
50/// ```
51/// # use devela::paste;
52/// macro_rules! method_new {
53///     ($ret:ident) => {
54///         paste! {
55///             #[doc = "Create a new `" $ret "` object."]
56///             pub fn new() -> $ret { todo!() }
57///         }
58///     };
59/// }
60///
61/// pub struct Paste {}
62///
63/// method_new!(Paste);  // expands to #[doc = "Create a new `Paste` object"]
64/// ```
65/// ---
66/// ---
67#[macro_export]
68#[cfg_attr(cargo_primary_package, doc(hidden))]
69macro_rules! paste {
70    ($($tt:tt)*) => {
71        $crate::code::__paste!{ $($tt)* }
72    }
73}
74#[doc(inline)]
75pub use paste;
76#[doc(hidden)] // dont export this
77pub use paste_crate::paste as __paste;