Drop can be automatically discarded when they go out of scope.
The drop operation is a no-op - it simply indicates to the compiler that this type
can be safely discarded.
Signature
Examples
WithoutDrop:
Drop:
Drop can be automatically discarded when they go out of scope.
The drop operation is a no-op - it simply indicates to the compiler that this type
can be safely discarded.
pub trait Drop
Drop:
struct Point {
x: u128,
y: u128,
}
fn foo(p: Point) {} // Error: `p` cannot be dropped
Drop:
#[derive(Drop)]
struct Point {
x: u128,
y: u128,
}
fn foo(p: Point) {} // OK: `p` is dropped at the end of the function
Was this page helpful?