Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7235125rwr; Tue, 2 May 2023 11:23:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7HX42F6xngauLhzgxpkTTKHWDMxLgK/9vvnqvKcNUFga1Dj6EJh92FVQBp9cgct8uWH76l X-Received: by 2002:a05:6a00:23cc:b0:640:f519:e1cc with SMTP id g12-20020a056a0023cc00b00640f519e1ccmr26676370pfc.34.1683051790773; Tue, 02 May 2023 11:23:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683051790; cv=none; d=google.com; s=arc-20160816; b=TFdTQN+ohalajzX2oTNZKqp+Uirnw3fD75cyokHR8rX33dpTwbGFBNW4Fo3nbyXVmf BJJv4PmxoqAzvrfk8mq2GOAcXkQbfu8/Vce0LglI9PlroKYsEOre9hi1Vy8hIgKDM+18 C8g1qnqSaWXsGTH3EPKjYmyCYvtgN+FXYkEvCoItsg+a3icEjXhNwrQk6uuaxrBWLrHa pNSbfQyEoJhb6GP0QWsKWynwRpKknt+ZbAga+XVXIe+KnXYlThMID6YDD8Oz+VyQJJvT 0XFNQ/yuIGu+dLHsXuZ/r0yvK4RWVBRcpxXTrklEYSvvCWPpnpg7M0yqaW/UTUR/ZEul ohZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=gRaJ+D8upH0CzVnGVpD0jcCp3qLvV1xzPMZYZq2YRko=; b=mAV2ntvrL68UjpM6u34JId+0OkmHbRLCUouNnA7sL+LFrpRoz2zQ1yaknUWtYLsMKr FmCJx1skxHWxUYe5tUuzQWuHxEUdGSKcUUNMFqyd88YJHsEf10YjJkBPs8r2S+Oa0iDZ /9uh2wg3zhPQjww7K0mQaby72JQno0gLxA+ZvQ1MWH/gm4TKP0ouOCZSEMUKxzFKvi62 LlsvN9Ee9UAlhgrfX0RXhhIKxaK5v9446W8qNZt29AKmnWFPXSguUnaMzJKsbZmu2+zf NYddqmDErus56fMKSv887gcrU27VCEh5xVjzcDptUe0T+2lnM+ejLgpeCk9/7VxUzyUf 52Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ryhl.io header.s=fm3 header.b=EyrPOioz; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Xk2rKxj0; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a63ea10000000b0051fadd81852si30665106pgi.540.2023.05.02.11.22.56; Tue, 02 May 2023 11:23:10 -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=@ryhl.io header.s=fm3 header.b=EyrPOioz; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=Xk2rKxj0; 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=NONE sp=NONE dis=NONE) header.from=ryhl.io Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234101AbjEBSQn (ORCPT + 99 others); Tue, 2 May 2023 14:16:43 -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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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