this post was submitted on 23 Jul 2026
15 points (100.0% liked)
Rust
8170 readers
35 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 3 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Using cells in your solution is smelly, when you can simply use two transparent wrappers with Ref or RefMut access, so you have actual compile-time checking instead of janky checking at runtime (which is also not zero-cost).
The allow/deny variants could themselves hold
&or&mutreferences too if we are going with that route. But it all depends on the precise problem OP is having and what is the best workable solution for it looks like.How is it a code smell? I'm pretty sure interior mutability is a well established design pattern. I'm not really familiar with the pattern you're describing using Ref/RefMut wrapping, could you show me what you mean?
Yeah I didn't want to pour a bunch of time into wrangling borrow checker stuff for a small code snippet.
Actually, I didn't notice your use of
clone()which is even worse.Here is what I had in mind. One can put the
T: Defaultbound on the wrappers themselves to simplify, or add potentially expensive transformations for non-Default types.Yeah what I wrote was just something to get the idea out, about having a list of Allowables.
I just fully read your code, and I like how you changed the Allowable api to have a deny and allow function instead of it being at the AllowList level. Honestly, I did not know mem::take was a function. I like how you got around cloning too.
Also, just so you know, you come off pretty rude. Just want to make sure you know that if you're not aware.