diff --git a/samples/rust/rust_print.rs b/samples/rust/rust_print.rs index 8b39d9cef6d1..67ed8ebf8e8e 100644 --- a/samples/rust/rust_print.rs +++ b/samples/rust/rust_print.rs @@ -15,6 +15,30 @@ struct RustPrint; +fn arc_print() -> Result { + use kernel::sync::*; + + let a = Arc::try_new(1)?; + let b = UniqueArc::try_new("hello, world")?; + + // Prints the value of data in `a`. + pr_info!("{}", a); + + // Uses ":?" to print debug fmt of `b`. + pr_info!("{:?}", b); + + let a: Arc<&str> = b.into(); + let c = a.clone(); + + // Uses `dbg` to print, will move `c` (for temporary debugging purposes). + dbg!(c); + + // Pretty-prints the debug formatting with lower-case hexadecimal integers. + pr_info!("{:#x?}", a); + + Ok(()) +} + impl kernel::Module for RustPrint { fn init(_module: &'static ThisModule) -> Result { pr_info!("Rust printing macros sample (init)\n"); @@ -43,6 +67,8 @@ fn init(_module: &'static ThisModule) -> Result { pr_cont!(" is {}", "continued"); pr_cont!(" with {}\n", "args"); + arc_print()?; + Ok(RustPrint) } }