2021-12-23 07:46:30 +11:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
//! Rust out-of-tree sample
|
|
|
|
|
|
|
|
use kernel::prelude::*;
|
|
|
|
|
|
|
|
module! {
|
|
|
|
type: RustOutOfTree,
|
2023-04-09 23:37:43 +10:00
|
|
|
name: b"rust_out_of_tree",
|
|
|
|
author: b"Rust for Linux Contributors",
|
|
|
|
description: b"Rust out-of-tree sample",
|
|
|
|
license: b"GPL",
|
2021-12-23 07:46:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
struct RustOutOfTree {
|
2022-08-06 22:05:09 +10:00
|
|
|
numbers: Vec<i32>,
|
2021-12-23 07:46:30 +11:00
|
|
|
}
|
|
|
|
|
2022-05-01 12:30:25 +10:00
|
|
|
impl kernel::Module for RustOutOfTree {
|
2022-12-19 06:47:44 +11:00
|
|
|
fn init(_module: &'static ThisModule) -> Result<Self> {
|
2021-12-23 07:46:30 +11:00
|
|
|
pr_info!("Rust out-of-tree sample (init)\n");
|
|
|
|
|
2022-08-06 22:05:09 +10:00
|
|
|
let mut numbers = Vec::new();
|
|
|
|
numbers.try_push(72)?;
|
|
|
|
numbers.try_push(108)?;
|
|
|
|
numbers.try_push(200)?;
|
|
|
|
|
|
|
|
Ok(RustOutOfTree { numbers })
|
2021-12-23 07:46:30 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for RustOutOfTree {
|
|
|
|
fn drop(&mut self) {
|
2022-08-06 22:05:09 +10:00
|
|
|
pr_info!("My numbers are {:?}\n", self.numbers);
|
2021-12-23 07:46:30 +11:00
|
|
|
pr_info!("Rust out-of-tree sample (exit)\n");
|
|
|
|
}
|
|
|
|
}
|