Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1226200rdb; Fri, 16 Feb 2024 08:53:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQ66p5GN18k8h1OMAlpdTjNwegJ6cYiUKSnE1oX6rTlqrvBJ6JwjRpgLU5XfI5ItBg23xWLVgphkrXg2BhwLcE4GvnIllD3OBjK3HBRA== X-Google-Smtp-Source: AGHT+IH+MSag/ie172rNaotGJDdAtP2lAy0X7NSK+PwZ5e6DegB1mNokZyZ8lEWNRyTmtPcxBTZ/ X-Received: by 2002:a17:906:e2d9:b0:a3c:a65:7bd8 with SMTP id gr25-20020a170906e2d900b00a3c0a657bd8mr3869825ejb.24.1708102434326; Fri, 16 Feb 2024 08:53:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708102434; cv=pass; d=google.com; s=arc-20160816; b=ypz8viSQhfbpK7U0N4HVzUsTgvvqx4MqGC7PiYq91Qsv567bFPy1eZjPevDFszYCbV rmtHHxnTfY1S+uedoGLjpJoRqiCNloCUtu9Q5R4kzE9293ZTyKmqdRwPAs92G4RRGhJK 9WbxAlQA7lHlLjiZZ+zQ4o0nYZY5kKXTFr+VklSj/ql56kRk4SIAZ6BJqYszgNMDli++ 3BewArGRbkmxxD06L3LemKRyuGf4Xn/NzrbppmqUgp1ImPPQsPXgren47r0hnib748mm +oZPjK8I+43SwLgyof7Q9M/yAcrWOrNIEspTvpVWH+LLNoqnnCkvMfPKSxBV7b8vZ4VK AE0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=UXS1gX5/Xy6PLxYM9RfnwBDoH8Pa3vSwtFNHUTxgmps=; fh=aGoqsfwad+cCvmmEte4rdr27JmphJjwzhB567idA3iA=; b=j3vRM4TtAZfLlh9jM9olLEco441lwyR2NZRSeylnd6j3bXa+kK6MfO1MU+0nII1+SO ND1dKcjJ82h3yzqfRNchVhcBO58vW/XBpdbNZlWUr9HMKjPlFIDa5YAw7XOlz4McRC4l PWXJKwaq0ckGsChBxLifYuN3k8RAGCe2zkVyEDIRmZww0UHKtaw2hnC7Sh7irifXo7UA zjLcnLJY6eEc3UgBYaOc2buz8cfoQhlzL9/VqiTUteDgN6U+gSnzjoIHOjeNw26EgHFK nsyFfmNGtoPlrS/qCg07B4eLwmhrB1EXZsVI+n1SVQGU/nr6jFmD+xiSn46PCdGdWf7C pZ/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FBYTll7I; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-68988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68988-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m19-20020a170906235300b00a3da44ada79si96866eja.30.2024.02.16.08.53.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 08:53:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-68988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=FBYTll7I; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-68988-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-68988-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 108481F23AAB for ; Fri, 16 Feb 2024 16:53:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59CDA13174B; Fri, 16 Feb 2024 16:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FBYTll7I" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF25912FB15 for ; Fri, 16 Feb 2024 16:53:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708102405; cv=none; b=gJYk6RiOfMaZyBFMYElbru215VnXFUMx3e8geDIaR5S9X2KjLoYjHox1dE5oX0teIVa8bWJYwxoZ1pJqtnYvOQB7YGGcfv76MgTq/2xzlUnMAlgfEyd2iT9215H23dvHSOL/IswPnxC2EgUL/0sPvo0+TQV2iCuBcK8qHENgzo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708102405; c=relaxed/simple; bh=+sI6/arw4pHUlSy2P7FUAboUipEszX2peP0Agji1zh0=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ine5Vedk9hFHqXHXNeWW493XzcD2lBtCumJ7AiH13Vnvri+6dza/MkYQPyTkpW3aMBfVIpVqB9ZYh8CrB8kGVyZ3+EQJhDL/5E03QpvSuaAkfhySOvq/iIsP5LcEeUPKsY7spYmU4m1pen5GtHyhb7H3SRabzhjgXOYgVwIbvh4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FBYTll7I; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60753c3fab9so27885487b3.0 for ; Fri, 16 Feb 2024 08:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708102403; x=1708707203; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UXS1gX5/Xy6PLxYM9RfnwBDoH8Pa3vSwtFNHUTxgmps=; b=FBYTll7IG/IXJaa9GAs4tCoembR4ylNRKm5NYRz7l8dmZYtFwwCliJdxQ6qbNI8ffb Q1GA1JFrCmQpZZQJ/ljtBDyosbcIN+H5O0uj9fJMkqhacVkh/YUxV4pk0yAFNC8UKdWg ec4OHnUst4yE8YDbOCWcjSXbfdfTT+gMIDYt4MG9Ba6ZwwPzThl3bNmXecYTLhB2GhC/ sqCbmV9MJzOpd1cEHOy+uKDLJ3eB6XhJV+WxCdhFsOlr0IGkR5Wbxye/ds/DA/U14PUZ xUfaEzGOZMAKuBBFBTt8mtqE3sRx9/L66bhy4L/Rng7NIIZSCJnTt4EmJKByr8XdeWlx 9h7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708102403; x=1708707203; 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=UXS1gX5/Xy6PLxYM9RfnwBDoH8Pa3vSwtFNHUTxgmps=; b=M8AMkzJfC7Yml8uJ5SH+ouJQ/TCpjVIGW9R79w/cpwTf4tqTLip8z0hnAAVHlpSaHx 1u/p+nLoTjsF1o2rKnirkUN41MBOX9OcjA8iCRIG8RCoxPvs1OHB9cPz7YfNc6qsFWjY CZFKxy69ysZ+VeGcpoKDtTefO0zbtZZAirB4GWpp+g49ljmiTHRukYMvCWwQdKHHko89 Szdocd8cYsUZc6upHuu/EDwmTxk/ba+96cb1zlXP6vlWp4eNfel7OxLeG7FJVtDujty6 0/CKOQzgPGNDGAT792EDRITRW2qRkO+h2W0VU9ZXtrV+xw4B+FcpgCmcghkYP7jLqmNy f5JA== X-Forwarded-Encrypted: i=1; AJvYcCW2VdFkQjiUQIihvENy09S8oSr1xnhZabWZ4/RMbwIIyVbwgT/AkuuGiCYr18SI0euAUiw2gMEy/ZBH1LWI4zas6nl/wB5Pg7ZsY22b X-Gm-Message-State: AOJu0YxZPQaWhR23UkUOugpxaquzNA48El3HRx5hpxyGlT8YIJDbyEYz mu4ndbaJBsBdgFSod/5X70ObbqR2jm1hl5ZpF9L9p754NU+pFI8slspLxaDW2hcK1IgY6GcBduT xrkO8uyVqKPgviA== X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a81:6c14:0:b0:5ff:6e82:ea31 with SMTP id h20-20020a816c14000000b005ff6e82ea31mr1184941ywc.3.1708102402988; Fri, 16 Feb 2024 08:53:22 -0800 (PST) Date: Fri, 16 Feb 2024 16:53:20 +0000 In-Reply-To: <20240214172505.5044-1-dakr@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240214172505.5044-1-dakr@redhat.com> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog Message-ID: <20240216165320.1820346-1-aliceryhl@google.com> Subject: Re: [PATCH v3] rust: str: add {make,to}_{upper,lower}case() to CString From: Alice Ryhl To: dakr@redhat.com Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, gary@garyguo.net, linux-kernel@vger.kernel.org, ojeda@kernel.org, rust-for-linux@vger.kernel.org, wedsonaf@gmail.com Content-Type: text/plain; charset="utf-8" > + pub fn make_ascii_lowercase(&mut self) { > + self.0.make_ascii_lowercase(); > + } It's important to note here that this doesn't remove or introduce NUL bytes. pub fn make_ascii_lowercase(&mut self) { // INVARIANT: This doesn't introduce or remove NUL bytes in the c // string. self.0.make_ascii_lowercase(); } Ditto for make_ascii_uppercase. (But not the to_* methods.) > + /// Returns a copy of this [`CString`] where each character is mapped to its > + /// ASCII lower case equivalent. > + /// > + /// ASCII letters 'A' to 'Z' are mapped to 'a' to 'z', > + /// but non-ASCII letters are unchanged. > + /// > + /// To lowercase the value in-place, use [`make_ascii_lowercase`]. > + /// > + /// [`make_ascii_lowercase`]: str::make_ascii_lowercase > + pub fn to_ascii_lowercase(&self) -> Result { > + let mut s = (*self).to_cstring()?; > + > + s.make_ascii_lowercase(); > + > + return Ok(s); > + } > + > + /// Returns a copy of this [`CString`] where each character is mapped to its > + /// ASCII upper case equivalent. > + /// > + /// ASCII letters 'a' to 'z' are mapped to 'A' to 'Z', > + /// but non-ASCII letters are unchanged. > + /// > + /// To uppercase the value in-place, use [`make_ascii_uppercase`]. > + /// > + /// [`make_ascii_uppercase`]: str::make_ascii_uppercase > + pub fn to_ascii_uppercase(&self) -> Result { > + let mut s = (*self).to_cstring()?; > + > + s.make_ascii_uppercase(); > + > + return Ok(s); > + } Please move these to `CStr` as well. > +impl DerefMut for CString { > + fn deref_mut(&mut self) -> &mut Self::Target { > + unsafe { CStr::from_bytes_with_nul_unchecked_mut(&mut *self.buf) } > + } > +} Needs a safety comment. impl DerefMut for CString { fn deref_mut(&mut self) -> &mut Self::Target { // SAFETY: A `CString` is always NUL-terminated and contains no // other NUL bytes. unsafe { CStr::from_bytes_with_nul_unchecked_mut(&mut *self.buf) } } } Alice