rust_out_of_tree: change example data to a `Vec`
This follows the contents of `samples/rust/rust_minimal.rs` in v9, which is the trimmed down version of v8 where `String` is not in `alloc` anymore. Now, the log looks like: [ 1.076945] rust_out_of_tree: Rust out-of-tree sample (init) [ 1.084944] rust_out_of_tree: My numbers are [72, 108, 200] [ 1.085944] rust_out_of_tree: Rust out-of-tree sample (exit) Link: https://lore.kernel.org/lkml/20220805154231.31257-27-ojeda@kernel.org/ Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
b1da1b5ff9
commit
48c6c6477a
|
@ -13,22 +13,25 @@ module! {
|
|||
}
|
||||
|
||||
struct RustOutOfTree {
|
||||
message: String,
|
||||
numbers: Vec<i32>,
|
||||
}
|
||||
|
||||
impl kernel::Module for RustOutOfTree {
|
||||
fn init(_name: &'static CStr, _module: &'static ThisModule) -> Result<Self> {
|
||||
pr_info!("Rust out-of-tree sample (init)\n");
|
||||
|
||||
Ok(RustOutOfTree {
|
||||
message: "on the heap!".try_to_owned()?,
|
||||
})
|
||||
let mut numbers = Vec::new();
|
||||
numbers.try_push(72)?;
|
||||
numbers.try_push(108)?;
|
||||
numbers.try_push(200)?;
|
||||
|
||||
Ok(RustOutOfTree { numbers })
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RustOutOfTree {
|
||||
fn drop(&mut self) {
|
||||
pr_info!("My message is {}\n", self.message);
|
||||
pr_info!("My numbers are {:?}\n", self.numbers);
|
||||
pr_info!("Rust out-of-tree sample (exit)\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue