rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gary Guo <gary@garyguo.net>
To: Alice Ryhl <aliceryhl@google.com>
Cc: nmi@metaspace.dk, alex.gaynor@gmail.com, alice@ryhl.io,
	benno.lossin@proton.me, bjorn3_gh@protonmail.com,
	boqun.feng@gmail.com, linux-kernel@vger.kernel.org,
	ojeda@kernel.org, patches@lists.linux.dev,
	rust-for-linux@vger.kernel.org, wedsonaf@gmail.com,
	yakoyoku@gmail.com
Subject: Re: [PATCH v2] rust: str: add conversion from `CStr` to `CString`
Date: Wed, 17 May 2023 19:09:28 +0100	[thread overview]
Message-ID: <20230517190928.08cfa0d5.gary@garyguo.net> (raw)
In-Reply-To: <20230516111202.2455529-1-aliceryhl@google.com>

On Tue, 16 May 2023 11:12:02 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> Andreas Hindborg <nmi@metaspace.dk> writes:
> > Alice Ryhl <alice@ryhl.io> writes:  
> >> On 5/8/23 13:41, Gary Guo wrote:  
> >>> On Wed,  3 May 2023 14:10:16 +0000
> >>> Alice Ryhl <aliceryhl@google.com> wrote:  
> >>>> These methods can be used to copy the data in a temporary c string into
> >>>> a separate allocation, so that it can be accessed later even if the
> >>>> original is deallocated.
> >>>>
> >>>> The API in this change mirrors the standard library API for the `&str`
> >>>> and `String` types. The `ToOwned` trait is not implemented because it
> >>>> assumes that allocations are infallible.  
> >>> How about add a `TryToOwned` trait to the kernel crate and implement
> >>> that trait for `CStr` instead?  
> >>
> >> Eh, I don't think it's worth it. It doesn't give anything new to the CStr api,
> >> and I think it's rather unlikely that someone will actually need to be generic
> >> over such a trait any time soon.  
> > 
> > It is just as valid as having `From<&str>` and `ToOwned<&str>`. While it
> > does not add anything in terms of function, it carries intention. I
> > think we should consider adding it at some point.
> > 
> > BR Andreas  
> 
> Sure, I think its quite reasonable to add new traits, I just don't think
> it should be part of this patch. Adding new traits makes it a
> significantly bigger change IMO, and my changes have an actual user down
> the road.
> 
> Alice

Personally I think `CStr` to `CString` conversion should be implemented
on top of `[u8]` to `Vec<u8>` conversion. Now we have two
conversions that fit in the concept of `TryToOwned`, so a trait is
warranted.

Best,
Gary

  reply	other threads:[~2023-05-17 18:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-03 14:10 [PATCH v2] rust: str: add conversion from `CStr` to `CString` Alice Ryhl
2023-05-03 19:01 ` Martin Rodriguez Reboredo
2023-05-08 11:41 ` Gary Guo
2023-05-08 20:29   ` Alice Ryhl
2023-05-15 18:12     ` Andreas Hindborg
2023-05-16 11:12       ` Alice Ryhl
2023-05-17 18:09         ` Gary Guo [this message]
2023-05-15 18:36 ` Andreas Hindborg
2023-05-31 17:09 ` Miguel Ojeda

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=20230517190928.08cfa0d5.gary@garyguo.net \
    --to=gary@garyguo.net \
    --cc=alex.gaynor@gmail.com \
    --cc=alice@ryhl.io \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nmi@metaspace.dk \
    --cc=ojeda@kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@gmail.com \
    --cc=yakoyoku@gmail.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).