From patchwork Thu Nov 10 16:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miguel Ojeda X-Patchwork-Id: 18215 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp252002wru; Thu, 10 Nov 2022 08:45:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM4cOoWuy5I9QI66UB15odUhVcCMTEdWtY7+7rQi/zOu0OqfJSRy05bF0L8nbzCxEVKlyPtW X-Received: by 2002:a17:907:a429:b0:7a6:a48b:5e52 with SMTP id sg41-20020a170907a42900b007a6a48b5e52mr58814222ejc.411.1668098706381; Thu, 10 Nov 2022 08:45:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668098706; cv=none; d=google.com; s=arc-20160816; b=sKbUsaYcnIBT5M1psuQOAcn4NeFaVqblkEt8uGIsloRwTs67WBL9X1hiuHFaKpFpL2 7OCQujanKkfONg1d4/9fogFtAic7PFSTaBFBCg6owEp87Dzsepm4NcvAYDs1a8QxZcHs Vg5GVC6OELON3UQitf0jWWI2VpzmgEF9HkTfxx71Eoj2Zy2KIXb/mft9rSxGfZLb7ely OBFmDhxoUtVpJ3uyW3HAeAmiV2qFyUkTSc+VErWtJI0qDkBGmfv6PKW5b8scKc9tOKIn 18jgYGtvhBigcrM8oweOrmhdA4wb644MtuQ4MrENnMWjuMwu7+NZBri4obJhimO3vsJc VT+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8FrNuK0IkU0HL5bgRPrz8xUBzj5CJaBgy53d1Jgff8I=; b=ttvujd7A8/pVe0CnZocPvGoni7Q1Gmk+N0iZy8e/uo0gU6xMom93NPyAdJIPyhxJhN 1aJ90t8G3emg54TIbiZLWMzygBogy2u6CakN6IiGdkhOiuzgFKkWkvwH4j9PgEejbLz6 jZVFbQzQicv+Arilf3ClVzbFsMwkq/MYVn0FLTxBPkQr+LJUMIzR+cuok0KHT4tdI4lR YvQPG7Iqu2Wy9z5JjwHbXFRTHExU/1S+WGE8C1TpwgdI8BqUwqwtGFPTlk7nNqXhUvy1 zS3WemuQ6CiAZyRGSKEBPlDIM/7mZM7op6Yzvfo1g+c6+13cOXe27hRpaIdDGO80g7pw eceQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=V1fkxyBu; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b007ae86742c3bsi6680825ejc.1009.2022.11.10.08.44.41; Thu, 10 Nov 2022 08:45:06 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=V1fkxyBu; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232471AbiKJQoE (ORCPT + 99 others); Thu, 10 Nov 2022 11:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232351AbiKJQn1 (ORCPT ); Thu, 10 Nov 2022 11:43:27 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A58E43AE2; Thu, 10 Nov 2022 08:43:01 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DAF0C61BCB; Thu, 10 Nov 2022 16:43:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 678EEC433D7; Thu, 10 Nov 2022 16:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668098580; bh=H8GrOu07IRuGrUGFNBmi30U0LGPQsGBzhM2gPsNjUkU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1fkxyBuVKLqkXCwarbt2nzk2Gmd07/5IZb172x8K6Iy7ZZK0piYHQxGtjJCvFZ8q Egl+ANyi1jtSNOuoAVyMVUn7rSeKu62QUS8uG1yNeqdQ+kDrAWvp82GYOJx0YHKWck lr/e+VWXG4RC7ejtRrDSGpYfNpXSBwAGrMQg7Bnb5C0xO19VpGmFTymLBid3wrPtx/ ZXk7aIs44xhFG4QWSt7kCoxPk9WwPBVZH9uM2K7i/1GcZ2hLuUh1wMR/+dmHhCwbMo F+z3N+/Vf2dX4jP31xl7zMAda7Tv7tuUDo4lJ4/4IG64eaxObhRxbFOYk8xUTftZA2 9AvF7s5SKzNWQ== From: Miguel Ojeda To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: [PATCH v1 14/28] rust: str: add `BStr` type Date: Thu, 10 Nov 2022 17:41:26 +0100 Message-Id: <20221110164152.26136-15-ojeda@kernel.org> In-Reply-To: <20221110164152.26136-1-ojeda@kernel.org> References: <20221110164152.26136-1-ojeda@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749128268995024157?= X-GMAIL-MSGID: =?utf-8?q?1749128268995024157?= From: Gary Guo Add the `BStr` type, which is a byte string without UTF-8 validity guarantee. It is simply an alias to `[u8]`, but has a more evident semantical meaning. Signed-off-by: Gary Guo [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- rust/kernel/str.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index e45ff220ae50..3aa1a0cb9bf8 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -4,6 +4,11 @@ use core::fmt; +/// Byte string without UTF-8 validity guarantee. +/// +/// `BStr` is simply an alias to `[u8]`, but has a more evident semantical meaning. +pub type BStr = [u8]; + /// Allows formatting of [`fmt::Arguments`] into a raw buffer. /// /// It does not fail if callers write past the end of the buffer so that they can calculate the