module! { type: RustPrint,
name: "rust_print",
authors: ["Rust for Linux Contributors"],
description: "Rust printing macros sample",
license: "GPL",
}
struct RustPrint;
#[expect(clippy::disallowed_macros)] fn arc_print() -> Result { use kernel::sync::*;
let a = Arc::new(1, GFP_KERNEL)?; let b = UniqueArc::new("hello, world", GFP_KERNEL)?;
// 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);
{ // `Arc` can be used to delegate dynamic dispatch and the following is an example. // Both `i32` and `&str` implement `Display`. This enables us to express a unified // behaviour, contract or protocol on both `i32` and `&str` into a single `Arc` of // type `Arc<dyn Display>`.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.