completed 04 traits

This commit is contained in:
2025-03-02 08:27:03 +05:30
parent 10fea65893
commit 7e998862fa
3 changed files with 42 additions and 1 deletions

View File

@@ -1,6 +1,28 @@
// TODO: implement a so-called "Drop bomb": a type that panics when dropped
// unless a certain operation has been performed on it.
// You can see the expected API in the tests below.
#[derive(Debug, Clone)]
pub struct DropBomb {
a: bool,
}
impl DropBomb {
fn new() -> DropBomb {
DropBomb { a: false }
}
fn defuse(&mut self) {
self.a = true;
}
}
impl Drop for DropBomb {
fn drop(&mut self) {
if !self.a {
panic!("Not Defused!!")
}
}
}
#[cfg(test)]
mod tests {