diff options
author | Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> | 2020-09-12 14:38:29 +0200 |
---|---|---|
committer | Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> | 2020-09-12 17:06:06 +0200 |
commit | 493d0d6440128a42b81fa4797212bf5966b9f54f (patch) | |
tree | af64a01138b2baa7454b4448168e0ef999a775a2 /drivers/char/rust_example/src/lib.rs | |
parent | e280b81cab4477f0709e9f519c86944af44a913c (diff) |
Parameter support
To have more flexibility, switch to a procedural macro instead.
Signed-off-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Diffstat (limited to 'drivers/char/rust_example/src/lib.rs')
-rw-r--r-- | drivers/char/rust_example/src/lib.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/drivers/char/rust_example/src/lib.rs b/drivers/char/rust_example/src/lib.rs index 56562b840d9c..e058124bb662 100644 --- a/drivers/char/rust_example/src/lib.rs +++ b/drivers/char/rust_example/src/lib.rs @@ -5,6 +5,26 @@ use kernel::prelude::*; +module!{ + typename: RustExample, + name: b"rust_example", + author: b"Rust for Linux Contributors", + description: b"An example kernel module written in Rust", + license: b"GPL v2", + params: { + my_bool: bool { + default_: true, + permissions: 0, + description: b"Example of bool", + }, + my_i32: i32 { + default_: 42, + permissions: 0o644, + description: b"Example of i32", + }, + }, +} + struct RustExample { message: String, } @@ -13,6 +33,9 @@ impl KernelModule for RustExample { fn init() -> KernelResult<Self> { println!("Rust Example (init)"); println!("Am I built-in? {}", !cfg!(MODULE)); + println!("Parameters:"); + println!(" my_bool: {}", my_bool.read()); + println!(" my_i32: {}", my_i32.read()); Ok(RustExample { message: "on the heap!".to_owned(), }) @@ -26,9 +49,3 @@ impl Drop for RustExample { } } -kernel_module!( - RustExample, - author: b"Rust for Linux Contributors", - description: b"An example kernel module written in Rust", - license: b"GPL v2" -); |