devela/code/util/
paste.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// devela::code::util::paste
//

/// <span class="stab portability" title="re-exported from the `paste` crate">`paste`</span>
/// Allows to paste identifiers together.
///
#[doc = "*Reexported from the [`paste`](https://docs.rs/paste)* crate.\n\n---"]
///
/// Within the `paste!` macro, identifiers inside `[<`...`>]` are pasted
/// together to form a single identifier.
///
/// # Examples
/// ```
/// # use devela::paste;
/// paste! {
///     // Defines a const called `QRST`.
///     const [<Q R S T>]: &str = "success!";
/// }
///
/// fn main() {
///     assert_eq!(
///         paste! { [<Q R S T>].len() },
///         8,
///     );
/// }
/// ```
///
/// ## Case conversion
///
/// Use `$var:lower` or `$var:upper` in the segment list to convert an
/// interpolated segment to lower- or uppercase as part of the paste. For
/// example, `[<ld_ $reg:lower _expr>]` would paste to `ld_bc_expr` if invoked
/// with `$reg=Bc`.
///
/// Use `$var:snake` to convert CamelCase input to snake\_case.
/// Use `$var:camel` to convert snake\_case to CamelCase. These compose,
/// so for example `$var:snake:upper` would give you SCREAMING\_CASE.
///
/// The precise Unicode conversions are as defined by [`str::to_lowercase`][0]
/// and [`str::to_uppercase`][1].
///
/// [0]: https://doc.rust-lang.org/core/primitive.str.html#method.to_lowercase
/// [1]: https://doc.rust-lang.org/core/primitive.str.html#method.to_uppercase
///
/// ## Pasting documentation strings
///
/// Within the `paste!` macro, arguments to a `#[doc ...]` attribute are
/// implicitly concatenated together to form a coherent documentation string.
///
/// ```
/// # use devela::paste;
/// macro_rules! method_new {
///     ($ret:ident) => {
///         paste! {
///             #[doc = "Create a new `" $ret "` object."]
///             pub fn new() -> $ret { todo!() }
///         }
///     };
/// }
///
/// pub struct Paste {}
///
/// method_new!(Paste);  // expands to #[doc = "Create a new `Paste` object"]
/// ```
/// ---
/// ---
#[macro_export]
#[cfg_attr(cargo_primary_package, doc(hidden))]
macro_rules! paste {
    ($($tt:tt)*) => {
        $crate::code::__paste!{ $($tt)* }
    }
}
#[doc(inline)]
pub use paste;
#[doc(hidden)] // dont export this
pub use paste_crate::paste as __paste;