completed 04 traits
This commit is contained in:
@@ -2,9 +2,10 @@
|
|||||||
// to get the code to compile.
|
// to get the code to compile.
|
||||||
|
|
||||||
pub fn summary(ticket: Ticket) -> (Ticket, Summary) {
|
pub fn summary(ticket: Ticket) -> (Ticket, Summary) {
|
||||||
(ticket, ticket.summary())
|
(ticket.clone(), ticket.summary())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Ticket {
|
pub struct Ticket {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
|
|||||||
@@ -1,10 +1,28 @@
|
|||||||
// TODO: implement the necessary traits to make the test compile and pass.
|
// TODO: implement the necessary traits to make the test compile and pass.
|
||||||
// You *can't* modify the test.
|
// You *can't* modify the test.
|
||||||
|
|
||||||
|
use std::ops::Add;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct WrappingU32 {
|
pub struct WrappingU32 {
|
||||||
value: u32,
|
value: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq for WrappingU32 {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.value == other.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add for WrappingU32 {
|
||||||
|
type Output = WrappingU32;
|
||||||
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
|
WrappingU32 {
|
||||||
|
value: self.value.wrapping_add(rhs.value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl WrappingU32 {
|
impl WrappingU32 {
|
||||||
pub fn new(value: u32) -> Self {
|
pub fn new(value: u32) -> Self {
|
||||||
Self { value }
|
Self { value }
|
||||||
|
|||||||
@@ -1,6 +1,28 @@
|
|||||||
// TODO: implement a so-called "Drop bomb": a type that panics when dropped
|
// TODO: implement a so-called "Drop bomb": a type that panics when dropped
|
||||||
// unless a certain operation has been performed on it.
|
// unless a certain operation has been performed on it.
|
||||||
// You can see the expected API in the tests below.
|
// 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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user