"Gary Guo" <[email protected]> writes: > On Fri May 29, 2026 at 9:41 AM BST, Andreas Hindborg wrote: >> For `Copy` parameter types it is more ergonomic to retrieve the >> parameter value by copy than through a shared reference. Change >> `ModuleParamAccess::value` to return `T` by copy when `T: Copy`, >> and rename the previous reference-returning accessor to >> `value_ref`. Update the in-tree caller in `rust_minimal`. >> >> Suggested-by: Alice Ryhl <[email protected]> >> Signed-off-by: Andreas Hindborg <[email protected]> >> --- >> This change was suggested during review of the rust null block series [1]. >> >> [1] https://lore.kernel.org/r/[email protected] >> --- >> rust/kernel/module_param.rs | 15 ++++++++++++++- >> samples/rust/rust_minimal.rs | 2 +- >> 2 files changed, 15 insertions(+), 2 deletions(-) >> >> diff --git a/rust/kernel/module_param.rs b/rust/kernel/module_param.rs >> index 6a8a7a875643..701210206bba 100644 >> --- a/rust/kernel/module_param.rs >> +++ b/rust/kernel/module_param.rs >> @@ -132,9 +132,12 @@ pub const fn new(default: T) -> Self { >> } >> >> /// Get a shared reference to the parameter value. >> + /// >> + /// Returns a reference to the value supplied at module load time, or a >> + /// reference to the default value if the parameter has not been set. >> // Note: When sysfs access to parameters are enabled, we have to pass >> in a >> // held lock guard here. >> - pub fn value(&self) -> &T { >> + pub fn value_ref(&self) -> &T { >> self.value.as_ref().unwrap_or(&self.default) >> } >> >> @@ -146,6 +149,16 @@ pub const fn as_void_ptr(&self) -> *mut c_void { >> } >> } >> >> +impl<T: Copy> ModuleParamAccess<T> { > > Instead of adding a new impl block, this should just be moved to immediately > after (or before) `value_ref` with a `where T: Copy` bound instead. > > This makes related code close together for readers of the code.
Will do. Best regards, Andreas Hindborg

