Skip to content

[Tracking/Asahi] Upstream-ready Rust changes #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: rust-next
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
38717bd
rust: kernel: Mark rust_fmt_argument as extern "C"
sulix Feb 14, 2023
bcfd851
soc: apple: rtkit: Add a private pointer to apple_rtkit_shmem
asahilina Jan 21, 2023
5f9a6ba
soc: apple: rtkit: Export non-devm init/free functions
asahilina Jan 21, 2023
3c3f227
drm/gem-shmem: Fix locking for drm_gem_shmem_get_pages_sgt()
asahilina Sep 7, 2022
a38c023
arm64: rust: Enable Rust support for AArch64
ojeda Jan 25, 2023
135e133
arm64: rust: Enable PAC support for Rust.
JamieCunliffe Jan 25, 2023
3ca7478
arm64: rust: Disable neon and fp target features.
JamieCunliffe Jan 25, 2023
4c9658b
rust: sync: impl {Debug,Display} for {Unique,}Arc
fbq Feb 7, 2023
a0fe4ac
sample: rust: print: Add sampe code for Arc printing
fbq Feb 7, 2023
d9eead4
rust: time: New module for timekeeping functions
asahilina Oct 19, 2022
dcc390a
rust: macros: Make expect_punct() return the Punct directly
asahilina Jan 26, 2023
02ce81c
rust: concat_idents: Allow :: paths in first argument
asahilina Nov 4, 2022
8c01902
rust: macros: Allow specifying multiple module aliases
asahilina Dec 5, 2022
3c3ce10
rust: ioctl: Add ioctl number manipulation functions
asahilina Sep 24, 2022
1a2e724
rust: sync: arc: implement Arc<dyn Any + Send + Sync>::downcast()
asahilina Feb 15, 2023
d5bbcf9
rust: Enable feature new_uninit for the kernel crate
asahilina Feb 11, 2023
051bf80
rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
asahilina Nov 11, 2022
5e05f75
rust: error: Add Error::to_ptr()
asahilina Sep 7, 2022
a1944a0
rust: error: Add Error::from_kernel_errno()
asahilina Feb 5, 2023
a901500
rust: error: Add to_result() helper
asahilina Feb 5, 2023
27f80ac
rust: error: Add a helper to convert a C ERR_PTR to a `Result`
May 13, 2021
7674653
rust: error: Add from_kernel_result!() macro
asahilina Feb 16, 2023
7400397
rust: Import upstream `alloc::vec::set_len_on_drop` module
asahilina Feb 16, 2023
a556d07
rust: Import upstream `alloc::vec::spec_extend` module
asahilina Feb 16, 2023
164f721
rust: alloc: vec: Add some try_* methods we need
ojeda Feb 16, 2023
38cd356
rust: xarray: Add an abstraction for XArray
asahilina Jan 11, 2023
0133449
rust: Add a Sealed trait
asahilina Feb 5, 2023
3653148
rust: device: Add an abstraction for devices
wedsonaf Nov 18, 2021
f476b2b
rust: io_pgtable: Add io_pgtable abstraction
asahilina Sep 7, 2022
f7708d0
rust: soc: apple: rtkit: Add Apple RTKit abstraction
asahilina Aug 17, 2022
b72447f
rust: Add `container_of` and `offset_of` macros
wedsonaf Apr 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sample: rust: print: Add sampe code for Arc printing
This both demonstrates the usage of different print format in Rust and
serves as a selftest for the `Display` and `Debug` implementation of
`Arc` and its friends.

Signed-off-by: Boqun Feng <[email protected]>
Reviewed-by: Björn Roy Baron <[email protected]>
Reviewed-by: Finn Behrens <[email protected]>
Reviewed-by: Vincenzo Palazzo <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Andreas Hindborg <[email protected]>
  • Loading branch information
fbq authored and asahilina committed Feb 16, 2023
commit a0fe4ac8d06044a165e8693bb552d676aab01bc7
26 changes: 26 additions & 0 deletions samples/rust/rust_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@ module! {

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`.
dbg!(c);

// Prints debug fmt with pretty-print "#" and number-in-hex "x".
pr_info!("{:#x?}", a);

Ok(())
}

impl kernel::Module for RustPrint {
fn init(_module: &'static ThisModule) -> Result<Self> {
pr_info!("Rust printing macros sample (init)\n");
Expand Down Expand Up @@ -43,6 +67,8 @@ impl kernel::Module for RustPrint {
pr_cont!(" is {}", "continued");
pr_cont!(" with {}\n", "args");

arc_print()?;

Ok(RustPrint)
}
}
Expand Down