[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87y0xvzcdi.fsf@kernel.org>
Date: Mon, 24 Feb 2025 14:43:53 +0100
From: Andreas Hindborg <a.hindborg@...nel.org>
To: "Daniel Almeida" <daniel.almeida@...labora.com>
Cc: "Miguel Ojeda" <ojeda@...nel.org>, "Alex Gaynor"
<alex.gaynor@...il.com>, "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo"
<gary@...yguo.net>, Björn Roy Baron
<bjorn3_gh@...tonmail.com>, "Benno
Lossin" <benno.lossin@...ton.me>, "Alice Ryhl" <aliceryhl@...gle.com>,
"Trevor Gross" <tmgross@...ch.edu>, "Masahiro Yamada"
<masahiroy@...nel.org>, "Nathan Chancellor" <nathan@...nel.org>,
"Nicolas Schier" <nicolas@...sle.eu>, "Luis Chamberlain"
<mcgrof@...nel.org>, <rust-for-linux@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, "Adam Bratschi-Kaye"
<ark.email@...il.com>, <linux-kbuild@...r.kernel.org>, "Petr Pavlu"
<petr.pavlu@...e.com>, "Sami Tolvanen" <samitolvanen@...gle.com>,
"Daniel Gomez" <da.gomez@...sung.com>, "Simona Vetter"
<simona.vetter@...ll.ch>, "Greg KH" <gregkh@...uxfoundation.org>,
<linux-modules@...r.kernel.org>
Subject: Re: [PATCH v7 5/6] rust: str: add radix prefixed integer parsing
functions
"Daniel Almeida" <daniel.almeida@...labora.com> writes:
> Hi Andreas,
>
>> On 18 Feb 2025, at 10:00, Andreas Hindborg <a.hindborg@...nel.org> wrote:
>>
>> Add the trait `ParseInt` for parsing string representations of integers
>> where the string representations are optionally prefixed by a radix
>> specifier. Implement the trait for the primitive integer types.
>>
>> Signed-off-by: Andreas Hindborg <a.hindborg@...nel.org>
>> ---
>> rust/kernel/str.rs | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 118 insertions(+)
>>
>> diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
>> index db272d2198fcc..8b0d814b47f52 100644
>> --- a/rust/kernel/str.rs
>> +++ b/rust/kernel/str.rs
>> @@ -945,3 +945,121 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
>> macro_rules! fmt {
>> ($($f:tt)*) => ( core::format_args!($($f)*) )
>> }
>> +
>> +pub mod parse_int {
>> + //! Integer parsing functions for parsing signed and unsigned integers
>> + //! potentially prefixed with `0x`, `0o`, or `0b`.
>> +
>> + use crate::prelude::*;
>> + use crate::str::BStr;
>> + use core::ops::Deref;
>> +
>> + /// Trait that allows parsing a [`&BStr`] to an integer with a radix.
>> + ///
>> + /// [`&BStr`]: kernel::str::BStr
>> + // This is required because the `from_str_radix` function on the primitive
>> + // integer types is not part of any trait.
>> + pub trait FromStrRadix: Sized {
>
> Is this supposed to be implemented by somebody else? Otherwise we should seal it,
> perhaps?
That is a good point. I did not intend for the user to implement this,
same for `ParseInt`. I will look into sealing them.
Best regards,
Andreas Hindborg
Powered by blists - more mailing lists