src/metaprogramming.rs

Sun, 27 Apr 2025 20:29:43 -0500

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 27 Apr 2025 20:29:43 -0500
changeset 94
1f19c6bbf07b
parent 75
e9f4550cfa18
permissions
-rw-r--r--

Fix build with stable rust.

For optimisations, build.rs now automatically sets a nightly cfg flag,
so problems with the nightly feature are avoided. It is still used for
required for additional nightly-only features.

57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
1 /*!
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
2 Metaprogramming tools
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
3 */
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
4
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
5 /// Reference `x` if so indicated by the first parameter.
75
e9f4550cfa18 Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
6 /// Typically to be used from another macro.
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
7 ///
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
8 /// ```ignore
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
9 /// maybe_ref!(ref, V) // ➡ &V
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
10 /// maybe_ref!(noref, V) // ➡ V
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
11 /// ```
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
12 macro_rules! maybe_ref {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
13 (ref, $x:expr) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
14 &$x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
15 };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
16 (noref, $x:expr) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
17 $x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
18 };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
19 (ref, $x:ty) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
20 &$x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
21 };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
22 (noref, $x:ty) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
23 $x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
24 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
25 }
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
26
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
27 /// Choose `a` if first argument is the literal `ref`, otherwise `b`.
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
28 // macro_rules! ifref {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
29 // (noref, $a:expr, $b:expr) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
30 // $b
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
31 // };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
32 // (ref, $a:expr, $b:expr) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
33 // $a
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
34 // };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
35 // }
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
36
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
37 /// Annotate `x` with a lifetime if the first parameter
75
e9f4550cfa18 Fix out-of-date references in doc comments
Tuomo Valkonen <tuomov@iki.fi>
parents: 59
diff changeset
38 /// Typically to be used from another macro.
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
39 ///
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
40 /// ```ignore
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
41 /// maybe_ref!(ref, &'a V) // ➡ &'a V
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
42 /// maybe_ref!(noref, &'a V) // ➡ V
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
43 /// ```
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
44 macro_rules! maybe_lifetime {
94
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
45 (ref, $x:ty) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
46 $x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
47 };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
48 (noref, &$lt:lifetime $x:ty) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
49 $x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
50 };
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
51 (noref, &$x:ty) => {
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
52 $x
1f19c6bbf07b Fix build with stable rust.
Tuomo Valkonen <tuomov@iki.fi>
parents: 75
diff changeset
53 };
57
1b3b1687b9ed Add direct products (Pair, RowOp, ColOp, DiagOp)
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff changeset
54 }

mercurial