From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA7F35962; Fri, 3 Oct 2025 23:26:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759533972; cv=none; b=LBsyuSsf8aG+rekBvZ+N6K7yxX/LajUSyCi0UclQK9PuIpudacH79yZCeb9r1kssQF7prXBkR5Sci2aV4aQU0Z4X/N+OiYruXN3JbZgLQRW1RIK2QkxAeJZMgqmhW3yQcgmF6DMM1t96Herw4O054IToPmKZT7mkva1hJBvWYt0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759533972; c=relaxed/simple; bh=gDIEjpiMrPLbEbZ8juu60qbu02+GBX90gGM6pJSF1ZY=; h=Mime-Version:Content-Type:Date:Message-Id:To:From:Subject:Cc: References:In-Reply-To; b=LoNov0gXpL6Edc7zOWT2qnm+5Au9oRIFdlxPLEI+kIX+wNEDSRCWM6btNlNkHwwniWKbtxX5yBE+JH71PnvapYFeIMYe/AS9mlWuejcNxiCqToHd1JELminXbujY4wDDVS1yTaisB0qUWRFOBaNPsxzpkSDhgBTjOpVnJoDuclM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QfpHNS1y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QfpHNS1y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5574C4CEF5; Fri, 3 Oct 2025 23:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759533972; bh=gDIEjpiMrPLbEbZ8juu60qbu02+GBX90gGM6pJSF1ZY=; h=Date:To:From:Subject:Cc:References:In-Reply-To:From; b=QfpHNS1yXq1WfgzZoJFUw4QZTHhvIUILRDrFQO9H68EeyVWG+0JQhj9UoE2DndC9C eQu+LEjaGsU/3traJdkHTBEzgj6g2idUSDR4uPpHyXUe58AAbALKg9Bpm/d/OFGpS9 ssEgyjZNu5I7E4CNuA0/Mq3xltXxAkSnoNkvSnN1gJRLnBf45YeA/Tc67HrZEEp3i8 RGttNwhjXcpxBJLeBBH/rezRDwkuqs5GUyzSBVhwU1QL99g1zx3q3YVFkqQaUJHPMA I3VoU8LJdv8BIKomtomc/BK047MORXNj0xbxH1HNTXbw0OdY4fLBm0Cbhi2cXAUgWt ZrA3uJ33kf1TA== Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sat, 04 Oct 2025 01:26:07 +0200 Message-Id: To: "Matthew Maurer" From: "Danilo Krummrich" Subject: Re: [PATCH 4/7] rust: debugfs: support blobs from smart pointers Cc: , , , , , , , , , , , , References: <20251003222729.322059-1-dakr@kernel.org> <20251003222729.322059-5-dakr@kernel.org> In-Reply-To: On Sat Oct 4, 2025 at 1:12 AM CEST, Matthew Maurer wrote: > On Fri, Oct 3, 2025 at 3:27=E2=80=AFPM Danilo Krummrich = wrote: >> +// Base implementation for any `T: AsBytes`. >> impl BinaryWriter for T { >> fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: usiz= e) -> Result { >> writer.write_slice_partial(self.as_bytes(), offset) >> } >> } >> >> +// Delegate for `Mutex`: Support a `T` with an outer mutex. >> impl BinaryWriter for Mutex { >> fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: usiz= e) -> Result { >> let guard =3D self.lock(); >> @@ -64,6 +69,56 @@ fn write_to_slice(&self, writer: &mut UserSliceWriter= , offset: usize) -> Result< >> } >> } >> >> +// Delegate for `Box`: Support a `Box` with no lock or an i= nner lock. >> +impl BinaryWriter for Box >> +where >> + T: BinaryWriter, >> + A: Allocator, >> +{ >> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: usiz= e) -> Result { >> + self.deref().write_to_slice(writer, offset) >> + } >> +} >> + >> +// Delegate for `Pin>`: Support a `Pin>` with no lo= ck or an inner lock. >> +impl BinaryWriter for Pin> >> +where >> + T: BinaryWriter, >> + A: Allocator, >> +{ >> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: usiz= e) -> Result { >> + self.deref().write_to_slice(writer, offset) >> + } >> +} >> + >> +// Delegate for `Arc`: Support a `Arc` with no lock or an inner l= ock. >> +impl BinaryWriter for Arc >> +where >> + T: BinaryWriter, >> +{ >> + fn write_to_slice(&self, writer: &mut UserSliceWriter, offset: usiz= e) -> Result { >> + self.deref().write_to_slice(writer, offset) >> + } >> +} > > For `Box`, `Pin performed is to deref, is there a reason that we couldn't have the > `File` object be *inside* the object, thus avoiding any need for > these? I can't see them causing trouble, but > > ``` > Box> > Pin>> > Arc> > ``` > > seem like they'd usually be fine. The one caveat I can think of is > that if you had other functions that wanted to take an `&Arc` for > operations on the Arc, then having an `Arc>` would be > suboptimal. Am I missing something? I think this way around is not compatible with scoped API. Besides that, there is a semantical difference between File> and Arc>, i.e. the file itself would become reference counted. > Depending on the use case I'm missing, would a blanket implementation > for `T: Deref` in this case and `DerefMut` later on make more sense? > That should contract these into a single definition and generalize to > e.g. `ListArc` without further code. It was also my first thought to generalize over T: Deref, but unfortunately= this does lead to conflicting implementations of BinaryWriter. >> +// Delegate for `Vec`: Support a `Vec` with an outer lock. >> +impl BinaryReaderMut for Vec >> +where >> + T: AsBytes + FromBytes, >> + A: Allocator, >> +{ >> + fn read_from_slice_mut( >> + &mut self, >> + reader: &mut UserSliceReader, >> + offset: usize, >> + ) -> Result { >> + let slice =3D self.as_mut_slice(); >> + > > Nit: This is safe, but it also requires `FromBytes`, and is &mut, &mut It already requires T: AsBytes + FromBytes above. Or do you mean something = else?