[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aBNKEewhCP8jRIZL@pollux>
Date: Thu, 1 May 2025 12:16:49 +0200
From: Danilo Krummrich <dakr@...nel.org>
To: Matthew Maurer <mmaurer@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Alice Ryhl <aliceryhl@...gle.com>, Trevor Gross <tmgross@...ch.edu>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Sami Tolvanen <samitolvanen@...gle.com>,
Timur Tabi <ttabi@...dia.com>, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org
Subject: Re: [PATCH v2 1/4] rust: debugfs: Bind DebugFS directory creation
On Wed, Apr 30, 2025 at 11:31:56PM +0000, Matthew Maurer wrote:
>
> + /// Create a DebugFS subdirectory.
> + ///
> + /// # Examples
> + ///
> + /// ```
> + /// # use kernel::c_str;
> + /// # use kernel::debugfs::Dir;
> + /// {
> + /// let parent = Dir::new(c_str!("parent"));
> + /// // parent exists in DebugFS here.
> + /// let child = parent.subdir(c_str!("child"));
> + /// // parent/child exists in DebugFS here.
> + /// }
> + /// // Neither exist here.
> + /// ```
> + pub fn subdir(&self, name: &CStr) -> Self {
> + Self::create(name, Some(self))
> + }
I think this should return a new type (SubDir), which is a transparent wrapper
of Dir and dereferences to Dir.
Subsequently, we can remove Dir::keep() implement SubDir::keep() instead. This
ensures that we can never call keep() on the root directory, which would always
be a bug.
As an alternative to the Deref impl, you can also implement
`From<SubDir> for Dir`, such that a SubDir can either be "kept" or converted to
a Dir. Probably, that's even better.
Powered by blists - more mailing lists