linux-imx/samples/rust/rust_minimal.rs
Greg Kroah-Hartman dfed1574cd Merge 1ef4cf5f98 ("rust: alloc: update module comment of alloc.rs") into android16-6.12
Steps on the way to 6.12.18

Resolves merge conflicts in:
	rust/kernel/types.rs
	scripts/Makefile.build

Change-Id: I1a0d7a30074e2532f53b9c9d4cf0e8346d57ffef
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
[Re-resolved rust/kernel/types.rs <mmaurer@google.com>]
Signed-off-by: Matthew Maurer <mmaurer@google.com>
2025-04-07 05:41:55 -07:00

39 lines
878 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: KVec<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 = KVec::new();
numbers.push(72, GFP_KERNEL)?;
numbers.push(108, GFP_KERNEL)?;
numbers.push(200, GFP_KERNEL)?;
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");
}
}