rust-out-of-tree-module/rust_out_of_tree.rs

38 lines
829 B
Rust

// SPDX-License-Identifier: GPL-2.0
//! Rust out-of-tree sample
use kernel::prelude::*;
module! {
type: RustOutOfTree,
name: b"rust_out_of_tree",
author: b"Rust for Linux Contributors",
description: b"Rust out-of-tree sample",
license: b"GPL",
}
struct RustOutOfTree {
numbers: Vec<i32>,
}
impl kernel::Module for RustOutOfTree {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Rust out-of-tree sample (init)\n");
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 numbers are {:?}\n", self.numbers);
pr_info!("Rust out-of-tree sample (exit)\n");
}
}