From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1376C77B73 for ; Tue, 2 May 2023 18:16:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234074AbjEBSQl (ORCPT ); Tue, 2 May 2023 14:16:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229575AbjEBSQk (ORCPT ); Tue, 2 May 2023 14:16:40 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45F6EC; Tue, 2 May 2023 11:16:38 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 378F85C00C7; Tue, 2 May 2023 14:16:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 02 May 2023 14:16:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ryhl.io; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm3; t= 1683051396; x=1683137796; bh=gRaJ+D8upH0CzVnGVpD0jcCp3qLvV1xzPMZ YZq2YRko=; b=EyrPOiozK/Fc8+rQe6EiQwZZvYGY40mKnr64LslwNMRgJiKYBLU ZsroAojo1M2fRvQwGgYaWCBfO3xRWzXiLofI7zg8p4PaInKuGdfyqPYdsdEn44Jv f7NtydfgtP0qmk+xxUvEtp4qs+bSkI6o56blF8KTuqgs8J4hQtAPuvP5hnrvjYFy 8GXRv0SQwYdVKp5Kp/g1OESSQm+HPOFOVT/b/3/ehNMXczNi4MpNiAu0iLSXP6bb HIngyn3Bj3Ypz/N5LeVa1ge+YTSqR5RKxBdOGttF3IRqfIoUyvvHal4UDb5cZGdG yq8mY4bPJN4vEM/lrtdQXCcXWnwQMiT37aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1683051396; x=1683137796; bh=gRaJ+D8upH0CzVnGVpD0jcCp3qLvV1xzPMZ YZq2YRko=; b=Xk2rKxj0nQIattvbHpT+OpTF4Dx015K7RvgQ0w6+ouZJ5X0Qgc9 1N+aysufQ5Rdwhx0h4+3BFROv8t3Hnm6l1f6wHCYVtR7y6MIZ4FcLuCMSt2Xyk9P K9r6NLVVGcMblWnJ9xBx4u44aW2GtThcxFr/+Z0gzQEQ1j3ko/qRRceHqBuY/Nq+ +JxSZM+MCcMjHv1eaiHPJrECi4kFq0cx+CerSooRJRAJMEQ/DCxxwVxUmvTBodXz 4k+m94I5BxVgJV/y0GGqMm/yxWi9X2gRWxLGK/NS2mrE0DFF3wyuVsIr9xRUTYBO TtsubKvepbFVOMFx+AxcHv88SqLGf2ZdZ6g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfedviedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthejredttdefjeenucfhrhhomheptehl ihgtvgcutfihhhhluceorghlihgtvgesrhihhhhlrdhioheqnecuggftrfgrthhtvghrnh epheduuddvteekvdektdduledugfffhfdugeejgeeuvdevtdetveejheehiefffeegnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlihgtvg esrhihhhhlrdhioh X-ME-Proxy: Feedback-ID: i56684263:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 May 2023 14:16:34 -0400 (EDT) Message-ID: Date: Tue, 2 May 2023 20:17:04 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH] rust: str: add conversion from `CStr` to `CString` Content-Language: en-US To: Benno Lossin , Wedson Almeida Filho Cc: Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=c3=b6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev References: <20230502125306.358283-1-aliceryhl@google.com> From: Alice Ryhl In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On 5/2/23 20:02, Benno Lossin wrote: > On 02.05.23 18:59, Wedson Almeida Filho wrote: >> On Tue, 2 May 2023 at 09:53, Alice Ryhl wrote: >>> >>> +impl<'a> TryFrom<&'a CStr> for CString { >>> + type Error = TryReserveError; >> >> Wouldn't `AllocError` make more sense? Or even Error (with ENOMEM value). >> >> `TryReserveError` is documented as "The error type for try_reserve >> methods." -- that fact the we use a `Vec` is an implementation detail, >> I feel it's better not to leak this fact through the public API. > > I agree, it should be `AllocError`. There is a `From for Error` > with `ENOMEM` as the value, so `AllocError` is the most compatible, since it > simply converts to `Error` via `?`. Sounds good to me. > Technically, `TryReserveError` represents two different kinds of errors: > - CapacityOverflow -- triggered when exceeding `isize::MAX` bytes of size > - AllocError -- memory allocation failed > > I think it is fine to coalesce these into `AllocError`, since allocating > `isize::MAX` might as well be considered an OOM error. In fact, the `isize::MAX` case is unreachable since that would require you to already have a `&CStr` of that size, which Rust does not allow. > With that fixed: > Reviewed-by: Benno Lossin Thanks both of you. I'll submit a v2 tomorrow. Alice