struct_field_names_as_array/
lib.rs

1#![doc = include_str!("../README.md")]
2
3/// Derives the [`FieldNamesAsArray`] trait.
4///
5/// # Panics
6///
7/// If the token stream is not coming from a named struct or if
8/// the `field_names_as_array` attribute is used wrongfully, deriving
9/// this macro will fail.
10///
11/// # Examples
12///
13/// ```
14/// use struct_field_names_as_array::FieldNamesAsArray;
15///
16/// #[derive(FieldNamesAsArray)]
17/// struct Foo {
18///     bar: String,
19///     baz: String,
20///     bat: String,
21/// }
22///
23/// assert_eq!(Foo::FIELD_NAMES_AS_ARRAY, ["bar", "baz", "bat"]);
24/// ```
25///
26#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
27pub use struct_field_names_as_array_derive::FieldNamesAsArray;
28
29/// Derives the [`FieldNamesAsSlice`] trait.
30///
31/// # Panics
32///
33/// If the token stream is not coming from a named struct or if
34/// the `field_names_as_array` attribute is used wrongfully, deriving
35/// this macro will fail.
36///
37/// # Examples
38///
39/// ```
40/// use struct_field_names_as_array::FieldNamesAsSlice;
41///
42/// #[derive(FieldNamesAsSlice)]
43/// struct Foo {
44///     bar: String,
45///     baz: String,
46///     bat: String,
47/// }
48///
49/// assert_eq!(Foo::FIELD_NAMES_AS_SLICE, ["bar", "baz", "bat"]);
50/// ```
51///
52#[cfg_attr(doc_cfg, doc(cfg(feature = "derive")))]
53pub use struct_field_names_as_array_derive::FieldNamesAsSlice;
54
55/// Exposes the `FIELD_NAMES_AS_ARRAY` constant.
56///
57/// This trait is designed to be derived rather than implemented by
58/// hand (though that'd be perfectly fine as well).
59/// Please refer to the [top-level](crate) documentation for more
60/// information.
61///
62pub trait FieldNamesAsArray<const N: usize> {
63    const FIELD_NAMES_AS_ARRAY: [&'static str; N];
64}
65
66/// Exposes the `FIELD_NAMES_AS_SLICE` constant.
67///
68/// This trait is designed to be derived rather than implemented by
69/// hand (though that'd be perfectly fine as well).
70/// Please refer to the [top-level](crate) documentation for more
71/// information.
72///
73pub trait FieldNamesAsSlice {
74    const FIELD_NAMES_AS_SLICE: &'static [&'static str];
75}