Re: [PATCH v8 0/4] rust: replace kernel::str::CStr w/ core::ffi::CStr

From: Alice Ryhl
Date: Thu Feb 20 2025 - 14:49:52 EST


On Wed, Feb 19, 2025 at 2:33 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
>
> On Wed, Feb 19, 2025 at 9:21 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
> >
> > On Tue, Feb 18, 2025 at 5:05 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> > >
> > > Gentle ping. Trevor, Alice, Benno: you all participated in the last
> > > round of review - I'd appreciate it if you could take a look at this
> > > series.
> >
> > The primary thing that comes to mind looking at this is that losing
> > the Display impl is pretty sad. Having to jump through hoops every
> > time you want to print a string isn't great :(
>
> There's the practical answer and the philosophical one. The former is
> that core::ffi::CStr doesn't impl Display. The latter is that Display
> implementations aren't meant to be lossy, and we shouldn't make it
> ergonomic to do things that might surprise the user.

I don't think there's any problem with a lossy Display impl. It's
supposed to be user-facing, and that's more or less what it requires.
Does kernel printing even require the string to be utf-8 in the first
place? I guess there's a mismatch about that here.

> We could add our own UnicodeCStr which could impl Display and be
> AsRef<CStr>. Do you think that should gate this work?

The solution I actually want is just for CStr to be Display, but
that's not something we can control on the kernel-side. I won't block
this change over it.

Alice