xref: /openbmc/linux/samples/rust/rust_print.rs (revision 7effbd18)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 //! Rust printing macros sample.
4 
5 use kernel::pr_cont;
6 use kernel::prelude::*;
7 
8 module! {
9     type: RustPrint,
10     name: "rust_print",
11     author: "Rust for Linux Contributors",
12     description: "Rust printing macros sample",
13     license: "GPL",
14 }
15 
16 struct RustPrint;
17 
18 impl kernel::Module for RustPrint {
19     fn init(_module: &'static ThisModule) -> Result<Self> {
20         pr_info!("Rust printing macros sample (init)\n");
21 
22         pr_emerg!("Emergency message (level 0) without args\n");
23         pr_alert!("Alert message (level 1) without args\n");
24         pr_crit!("Critical message (level 2) without args\n");
25         pr_err!("Error message (level 3) without args\n");
26         pr_warn!("Warning message (level 4) without args\n");
27         pr_notice!("Notice message (level 5) without args\n");
28         pr_info!("Info message (level 6) without args\n");
29 
30         pr_info!("A line that");
31         pr_cont!(" is continued");
32         pr_cont!(" without args\n");
33 
34         pr_emerg!("{} message (level {}) with args\n", "Emergency", 0);
35         pr_alert!("{} message (level {}) with args\n", "Alert", 1);
36         pr_crit!("{} message (level {}) with args\n", "Critical", 2);
37         pr_err!("{} message (level {}) with args\n", "Error", 3);
38         pr_warn!("{} message (level {}) with args\n", "Warning", 4);
39         pr_notice!("{} message (level {}) with args\n", "Notice", 5);
40         pr_info!("{} message (level {}) with args\n", "Info", 6);
41 
42         pr_info!("A {} that", "line");
43         pr_cont!(" is {}", "continued");
44         pr_cont!(" with {}\n", "args");
45 
46         Ok(RustPrint)
47     }
48 }
49 
50 impl Drop for RustPrint {
51     fn drop(&mut self) {
52         pr_info!("Rust printing macros sample (exit)\n");
53     }
54 }
55