macro_rules! configfs_attrs {
(
container: $container:ty,
data: $data:ty,
attributes: [
$($name:ident: $attr:literal),* $(,)?
] $(,)?
) => { ... };
(
container: $container:ty,
data: $data:ty,
child: $child:ty,
attributes: [
$($name:ident: $attr:literal),* $(,)?
] $(,)?
) => { ... };
(count:
@container($container:ty),
@data($data:ty),
@child($($child:ty)?),
@no_child($($no_child:ident)?),
@attrs($($aname:ident $aattr:literal)*),
@eat($name:ident $attr:literal, $($rname:ident $rattr:literal,)*),
@assign($($assign:block)*),
@cnt($cnt:expr),
) => { ... };
(count:
@container($container:ty),
@data($data:ty),
@child($($child:ty)?),
@no_child($($no_child:ident)?),
@attrs($($aname:ident $aattr:literal)*),
@eat(),
@assign($($assign:block)*),
@cnt($cnt:expr),
) => { ... };
(final:
@container($container:ty),
@data($data:ty),
@child($($child:ty)?),
@no_child($($no_child:ident)?),
@attrs($($name:ident $attr:literal)*),
@assign($($assign:block)*),
@cnt($cnt:expr),
) => { ... };
}
Expand description
Define a list of configfs attributes statically.
Invoking the macro in the following manner:
ⓘ
let item_type = configfs_attrs! {
container: configfs::Subsystem<Configuration>,
data: Configuration,
child: Child,
attributes: [
message: 0,
bar: 1,
],
};
Expands the following output:
ⓘ
let item_type = {
static CONFIGURATION_MESSAGE_ATTR: kernel::configfs::Attribute<
0,
Configuration,
Configuration,
> = unsafe {
kernel::configfs::Attribute::new({
const S: &str = "message\u{0}";
const C: &kernel::str::CStr = match kernel::str::CStr::from_bytes_with_nul(
S.as_bytes()
) {
Ok(v) => v,
Err(_) => {
core::panicking::panic_fmt(core::const_format_args!(
"string contains interior NUL"
));
}
};
C
})
};
static CONFIGURATION_BAR_ATTR: kernel::configfs::Attribute<
1,
Configuration,
Configuration
> = unsafe {
kernel::configfs::Attribute::new({
const S: &str = "bar\u{0}";
const C: &kernel::str::CStr = match kernel::str::CStr::from_bytes_with_nul(
S.as_bytes()
) {
Ok(v) => v,
Err(_) => {
core::panicking::panic_fmt(core::const_format_args!(
"string contains interior NUL"
));
}
};
C
})
};
const N: usize = (1usize + (1usize + 0usize)) + 1usize;
static CONFIGURATION_ATTRS: kernel::configfs::AttributeList<N, Configuration> =
unsafe { kernel::configfs::AttributeList::new() };
{
const N: usize = 0usize;
unsafe { CONFIGURATION_ATTRS.add::<N, 0, _>(&CONFIGURATION_MESSAGE_ATTR) };
}
{
const N: usize = (1usize + 0usize);
unsafe { CONFIGURATION_ATTRS.add::<N, 1, _>(&CONFIGURATION_BAR_ATTR) };
}
static CONFIGURATION_TPE:
kernel::configfs::ItemType<configfs::Subsystem<Configuration> ,Configuration>
= kernel::configfs::ItemType::<
configfs::Subsystem<Configuration>,
Configuration
>::new_with_child_ctor::<N,Child>(
&THIS_MODULE,
&CONFIGURATION_ATTRS
);
&CONFIGURATION_TPE
}