Skip to content

Unclonable Reply #403

@rarensu

Description

@rarensu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions