mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-15 16:24:13 +08:00
b13c9880f9
Instead of taking binary string literals, take string ones instead, making it easier for users to define a module, i.e. instead of calling `module!` like: module! { ... name: b"rust_minimal", ... } now it is called as: module! { ... name: "rust_minimal", ... } Module names, aliases and license strings are restricted to ASCII only. However, the author and the description allows UTF-8. For simplicity (avoid parsing), escape sequences and raw string literals are not yet handled. Link: https://github.com/Rust-for-Linux/linux/issues/252 Link: https://lore.kernel.org/lkml/YukvvPOOu8uZl7+n@yadro.com/ Signed-off-by: Gary Guo <gary@garyguo.net> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
39 lines
852 B
Rust
39 lines
852 B
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//! Rust minimal sample.
|
|
|
|
use kernel::prelude::*;
|
|
|
|
module! {
|
|
type: RustMinimal,
|
|
name: "rust_minimal",
|
|
author: "Rust for Linux Contributors",
|
|
description: "Rust minimal sample",
|
|
license: "GPL",
|
|
}
|
|
|
|
struct RustMinimal {
|
|
numbers: Vec<i32>,
|
|
}
|
|
|
|
impl kernel::Module for RustMinimal {
|
|
fn init(_module: &'static ThisModule) -> Result<Self> {
|
|
pr_info!("Rust minimal sample (init)\n");
|
|
pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
|
|
|
|
let mut numbers = Vec::new();
|
|
numbers.try_push(72)?;
|
|
numbers.try_push(108)?;
|
|
numbers.try_push(200)?;
|
|
|
|
Ok(RustMinimal { numbers })
|
|
}
|
|
}
|
|
|
|
impl Drop for RustMinimal {
|
|
fn drop(&mut self) {
|
|
pr_info!("My numbers are {:?}\n", self.numbers);
|
|
pr_info!("Rust minimal sample (exit)\n");
|
|
}
|
|
}
|