From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Timur Tabi <ttabi@nvidia.com>
Cc: "lossin@kernel.org" <lossin@kernel.org>,
"ojeda@kernel.org" <ojeda@kernel.org>,
"aliceryhl@google.com" <aliceryhl@google.com>,
"dakr@kernel.org" <dakr@kernel.org>,
"rust-for-linux@vger.kernel.org"
<rust-for-linux@vger.kernel.org>
Subject: Re: [PATCH v4] rust: introduce sfile macro for succinct code tracing
Date: Sat, 21 Jun 2025 18:59:23 +0200 [thread overview]
Message-ID: <CANiq72m1W6Do4z0qjKmzxSbYT3az_x1DKZ5C3eLABsPRv55EwQ@mail.gmail.com> (raw)
In-Reply-To: <579273832b4accc4cd989d5182f3179c9950966f.camel@nvidia.com>
On Wed, Jun 18, 2025 at 10:05 PM Timur Tabi <ttabi@nvidia.com> wrote:
>
> I'm having trouble coding this up. I have this so far, but it doesn't compile:
(snip)
> 492 | unsafe { core::str::from_utf8_unchecked(p) }
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Option<&str>`, found `&str`
If you are asking about that last line, you need to return a `Some(...)`.
If you are asking in general, then since now you can return `None`,
you can just call the safe `from_utf8` and convert to an `Option`,
which also allows you to avoid the `is_ascii` call, and also allows
you to return `None` in other cases above too (instead of panicking).
That also allows you to keep the macro straightforward and small.
I hope that helps.
Cheers,
Miguel
next prev parent reply other threads:[~2025-06-21 16:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 19:34 [PATCH v4] rust: introduce sfile macro for succinct code tracing Timur Tabi
2025-06-16 21:03 ` Miguel Ojeda
2025-06-17 7:29 ` Benno Lossin
2025-06-17 7:54 ` Miguel Ojeda
2025-06-18 20:05 ` Timur Tabi
2025-06-21 16:59 ` Miguel Ojeda [this message]
2025-06-26 16:30 ` Timur Tabi
2025-06-26 20:57 ` Miguel Ojeda
2025-06-18 20:07 ` Timur Tabi
2025-06-21 16:47 ` Miguel Ojeda
2025-06-18 11:20 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANiq72m1W6Do4z0qjKmzxSbYT3az_x1DKZ5C3eLABsPRv55EwQ@mail.gmail.com \
--to=miguel.ojeda.sandonis@gmail.com \
--cc=aliceryhl@google.com \
--cc=dakr@kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=ttabi@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).