[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH5fLgiwRDcyaxbcUNY8M1c_w11vkCWyRfqVVrN9Sgc7XYT0xw@mail.gmail.com>
Date: Thu, 25 Jan 2024 10:08:35 +0100
From: Alice Ryhl <aliceryhl@...gle.com>
To: Danilo Krummrich <dakr@...hat.com>
Cc: ojeda@...nel.org, alex.gaynor@...il.com, wedsonaf@...il.com,
boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me, a.hindborg@...sung.com,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] rust: str: add to_ascii_{upper,lower}case() to CString
On Mon, Jan 22, 2024 at 7:46 PM Danilo Krummrich <dakr@...hat.com> wrote:
> + /// Converts the whole CString to lowercase.
> + pub fn to_ascii_lowercase(&mut self) {
> + self.buf.make_ascii_lowercase();
> + }
> +
> + /// Converts the whole CString to uppercase.
> + pub fn to_ascii_uppercase(&mut self) {
> + self.buf.make_ascii_uppercase();
> + }
> }
It looks like these methods are defined on `CString`. However, there's
no requirement that you need *ownership* of the c string to change its
contents - you just need mutable access.
I think it would make more sense to introduce an `impl DerefMut for
CString` that returns a `&mut CStr`, and then define these methods on
`CStr` as `&mut self`. That way, you can still call them on `CString`,
but you can also call it on other mutable c strings.
Alice
Powered by blists - more mailing lists