How to make a type only movable (move) but not copyable (Copy) in Rust?
Hello everyone! I recently started learning Rust and encountered the concepts of ownership and the Copy and Clone traits. I think I understand that primitive types like i32 or bool implement Copy, so when assigned they are copied and the original remains accessible. And more complex types, like String, are only Clone, and when assigned they are moved.
But I have a question: can I create my own custom type (for example, a struct) that will behave like String — that is, it will only be movable, and it cannot be accidentally copied? For example, I want to create a type that represents a unique identifier or some resource that should not be duplicated. If I simply declare a struct and add derive(Clone, Copy), it will be copied on every
No answers yet.
Log in to leave an answer