completed 04 traits
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user