Macro kernel::define_fs_params
source · [−]macro_rules! define_fs_params {
($data_type:ty, $({$($t:tt)*}),+ $(,)?) => { ... };
(@handlers $data_type:ty, $({$($t:tt)*},)*) => { ... };
(@handler $data_type:ty, enum, $name:expr, $opts:expr, $closure:expr) => { ... };
(@handler $data_type:ty, $type:ident, $name:expr, $closure:expr) => { ... };
(@specs $({$($t:tt)*},)*) => { ... };
(@spec enum, $name:expr, [$($opts:tt)*], $closure:expr) => { ... };
(@spec $type:ident, $name:expr, $closure:expr) => { ... };
(@c_str_first $(($first:expr, $second:expr)),+ $(,)?) => { ... };
}
Expand description
Defines the file system parameters of a given file system context.
Examples
#[derive(Default)]
struct State {
flag: Option<bool>,
flag_no: Option<bool>,
bool_value: Option<bool>,
u32_value: Option<u32>,
i32_value: Option<i32>,
u64_value: Option<u64>,
str_value: Option<CString>,
enum_value: Option<u32>,
}
fn set_u32(s: &mut Box<State>, v: u32) -> Result {
s.u32_value = Some(v);
Ok(())
}
struct Example;
#[vtable]
impl fs::Context<Self> for Example {
type Data = Box<State>;
kernel::define_fs_params! {Box<State>,
{flag, "flag", |s, v| { s.flag = Some(v); Ok(()) } },
{flag_no, "flagno", |s, v| { s.flag_no = Some(v); Ok(()) } },
{bool, "bool", |s, v| { s.bool_value = Some(v); Ok(()) } },
{u32, "u32", set_u32 },
{u32oct, "u32oct", set_u32 },
{u32hex, "u32hex", set_u32 },
{s32, "s32", |s, v| { s.i32_value = Some(v); Ok(()) } },
{u64, "u64", |s, v| { s.u64_value = Some(v); Ok(()) } },
{string, "string", |s, v| {
s.str_value = Some(CString::try_from_fmt(fmt!("{v}"))?);
Ok(())
}},
{enum, "enum", [("first", 10), ("second", 20)], |s, v| {
s.enum_value = Some(v);
Ok(())
}},
}
fn try_new() -> Result<Self::Data> {
Ok(Box::try_new(State::default())?)
}
}