Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp524391rwd; Tue, 16 May 2023 04:36:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7YloxWckL9qBBJ1qqqC8Z2oWHR+G4+fLYQhKc1uJiJ0oJCKvXwNg0CPPB0pa/v2xj0D4Uq X-Received: by 2002:a17:90a:3c8f:b0:247:bdd3:a039 with SMTP id g15-20020a17090a3c8f00b00247bdd3a039mr37143382pjc.8.1684237003115; Tue, 16 May 2023 04:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684237003; cv=none; d=google.com; s=arc-20160816; b=cuUe24Uu8fJEMAP56k0kOjOaCe1uW1kg+iGNdUsANbmwqi5uBHiS/itIrjlCP14K87 3KBmBiue/Rudt4/0yXQHXUIjGPAn8Pvco15AtTG1DqVimMlMbSEG7Ole7GXoVkvb9Rso vLvAVg7pFG1iJAhygFu+GUmNAy9t8MspGX2/JEfnhktQzweEe/zXjIQyU3/l1Niz1ibQ Gg319FsslcOeYqPAFi9b8tcqxJsDySqPWVxx76j3+ZHe6kS2WZgbSOUW5QcAs1f76r8C EuOBQbPzrBqP4LPzSpgTqRpEnNudPoWtorNXjJ4/YBlcqhe6PPvS9sv3KWm33YX6A0dN q5uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=sEUQpMHb6dJRirsjs02VRZsGdmT007slrG/7m3ecq4A=; b=lC0C6vi8FDwLWHKPlvPCyjHFj0VQzqCpS49UolXVAYLmV1EiZRNyLkexgRj6rHSI6U javOF1I81Ta4ZU62SXESpFGdJCu5jlf8FnHaln6dR6IQL95WIDPRjhGfgRA8/uETTMrF 77+BqF4Jh9+vtS2O016k0B99NMyh06+8C63gbxsi8YooNv2ljE2BLJK25lnWrtjR+W9x 8Ulfzl+HAATmhs/7R+uHopRYk8qssAplmuZd83rhOiPQGnl5zWD1cfEIUERIpXHrwcKK 1z8FHIG/YjO0ULO+1WXlfsQyz2Zn5sn+7yVYw4a3lR/2DsILVkgTD18nckkM6lIbJbu5 xPVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jTh2sQy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s193-20020a6377ca000000b00530716f3674si13967420pgc.526.2023.05.16.04.36.30; Tue, 16 May 2023 04:36:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=jTh2sQy0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232801AbjEPLON (ORCPT + 99 others); Tue, 16 May 2023 07:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232887AbjEPLNy (ORCPT ); Tue, 16 May 2023 07:13:54 -0400 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CBAD1997 for ; Tue, 16 May 2023 04:13:03 -0700 (PDT) Received: by mail-wr1-x449.google.com with SMTP id ffacd0b85a97d-3063394ae41so5045296f8f.2 for ; Tue, 16 May 2023 04:13:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684235525; x=1686827525; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sEUQpMHb6dJRirsjs02VRZsGdmT007slrG/7m3ecq4A=; b=jTh2sQy0h/wnTK3qlXXk0iLSLxxkkq3JJYemyleO0akNJycR3xdqBSpFNtuP78sZPH q1z/GaeVqh9f2wSvYHQqSuSK7Bnt7Fu3exPaDiHHDDRttWsjp+vLnZlEPiweSaqgYXGs w8cnMdF+arz1/vqXlDr6fqPt/uNxzKSj4h15+wWoA70j/0yrHfTLjW5ETXWnsjsuk/Gx dkH36a5oiSpgOQuj1kffDVVXxBdYnIH+/IrQ//0LrMqG6OGLj3rCv13LncGf0/iaSpk6 tgSXGNexxLB2X+dNoIuTwdn2UNfplnB30pKsU61QfAH4pzhHPPxixiGt4jrRPoGXosGM L5zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684235525; x=1686827525; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sEUQpMHb6dJRirsjs02VRZsGdmT007slrG/7m3ecq4A=; b=Lr3MnutjkKas1zbE97Rlo3mkGeyorgHXLmMSysfUe2/8O2z55U/xx8xAYvMPiMYgLn 5alxSKc2nBTV3ehkcx4WHCUdBGu3RCr7+QxydM4H3lJo0TI06Ek1QTTk1S/a6M9kQusx TGjSO3qfTvMHO5pJHPEx4qUWeLk7FNxRlWzJmYEu2T6kGsMo3h9tIkkisiNZBcJo8kGI bTfOvOVku08MZLgT8QsKrATlHJf7rWN5U/4zcjt24EzOujnMnmT8GOvAfpPppfn+yCuO BZ4r7DWiyVKMo96WwuaeOqgW/nyv/+NxukWD0D/vo7IqUzOxDdzJT/CdzyMjegdwhXUm VZOg== X-Gm-Message-State: AC+VfDyKIwfRZniDHVU1MKjXptCfwVSspF0627BPdx2GDdwbZs5Yjgk1 vod83M/UlXHJmTIvcPPsPzDG+VnT0CZL9C8= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:6c8]) (user=aliceryhl job=sendgmr) by 2002:a5d:4ac4:0:b0:307:cea0:ee9a with SMTP id y4-20020a5d4ac4000000b00307cea0ee9amr2239352wrs.7.1684235525305; Tue, 16 May 2023 04:12:05 -0700 (PDT) Date: Tue, 16 May 2023 11:12:02 +0000 In-Reply-To: <871qjhe9xh.fsf@metaspace.dk> Mime-Version: 1.0 References: <871qjhe9xh.fsf@metaspace.dk> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Message-ID: <20230516111202.2455529-1-aliceryhl@google.com> Subject: Re: [PATCH v2] rust: str: add conversion from `CStr` to `CString` From: Alice Ryhl To: nmi@metaspace.dk Cc: alex.gaynor@gmail.com, alice@ryhl.io, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, linux-kernel@vger.kernel.org, ojeda@kernel.org, patches@lists.linux.dev, rust-for-linux@vger.kernel.org, wedsonaf@gmail.com, yakoyoku@gmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andreas Hindborg writes: > Alice Ryhl writes: >> On 5/8/23 13:41, Gary Guo wrote: >>> On Wed, 3 May 2023 14:10:16 +0000 >>> Alice Ryhl 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