fuser icon indicating copy to clipboard operation
fuser copied to clipboard

Unclonable Reply

Open rarensu opened this issue 3 months ago • 0 comments

So I was thinking, what if someone, somehow, managed to implement a Clone-like operation on ReplyX? That would cause chaos, for sure: when one of the clones gets dropped, it would send a redundant error message to the kernel. So, I over-engineered a way to prevent that.

#[derive(Debug)]
struct DoNotCloneMe;

#[derive(Debug)]
pub(crate) struct ReplyX {
    ...
    /// marker that says DO NOT CLONE ME
    _no_clone: DoNotCloneMe,
}

Since DoNotCloneMe is private, it can't be constructed, and since it doesn't implement Clone, one cannot #[derive(Clone)] on ReplyX. Finally, since it is zero-sized, so it shouldn't affect performance in any way. I think it's clever. It makes it much harder for developers to accidentally abuse ReplyX objects.

As far as I know, this is a solution to a problem that only exists in my mind. Probably, this issue can be safely closed. I just wanted to share.

rarensu avatar Sep 16 '25 17:09 rarensu