Re: [PATCH v2 2/2] sample: rust: print: Add sampe code for Arc printing

From: Miguel Ojeda
Date: Wed Feb 08 2023 - 10:19:21 EST


On Tue, Feb 7, 2023 at 7:52 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
>
> + // Uses `dbg` to print, will move `c`.
> + dbg!(c);

Perhaps:

// Uses `dbg` to print, will move `c` (for temporary debugging purposes).
dbg!(c);

To make it clear it is not meant to be usually committed into the tree.

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

Apparently, `:#x?` is a bit of an accident: `#` means "alternate"
form, but it turns out it applies to both `x` and `?`, i.e. it is not
that `#` alone implies pretty-printing.

Given the above and that there are improvements under discussion
upstream, perhaps we could avoid giving details for the moment and
just say what it does as a whole, e.g.

// Pretty-prints the debug formatting with lower-case hexadecimal integers.
pr_info!("{:#x?}", a);

Some links for those interested:
https://doc.rust-lang.org/std/fmt/index.html#sign0,
https://github.com/rust-lang/rust/issues/75766,
https://github.com/rust-lang/rust/pull/99138#issuecomment-1385331055
and https://github.com/rust-lang/libs-team/issues/165.

Finally, there is a small typo in the commit title. What about:

rust: samples: print: add sample code for `Arc` printing

I can change these bits on my side if you want & agree with them, to
avoid a v3 just for this.

Thanks for these patches, Boqun!

Cheers,
Miguel