completed final 04 traits exercise
This commit is contained in:
@@ -8,3 +8,88 @@
|
||||
// It should be possible to print its debug representation.
|
||||
//
|
||||
// Tests are located in the `tests` folder—pay attention to the visibility of your types and methods.
|
||||
|
||||
use std::ops::Add;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SaturatingU16 {
|
||||
value: u16,
|
||||
}
|
||||
|
||||
impl From<u16> for SaturatingU16 {
|
||||
fn from(value: u16) -> Self {
|
||||
return SaturatingU16 { value };
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u8> for SaturatingU16 {
|
||||
fn from(value: u8) -> Self {
|
||||
return SaturatingU16 {
|
||||
value: value.into(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&u16> for SaturatingU16 {
|
||||
fn from(value: &u16) -> Self {
|
||||
return SaturatingU16 {
|
||||
value: value.clone(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&u8> for SaturatingU16 {
|
||||
fn from(value: &u8) -> Self {
|
||||
return SaturatingU16 {
|
||||
value: value.clone().into(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for SaturatingU16 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
SaturatingU16 {
|
||||
value: self.value.saturating_add(rhs.value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<u16> for SaturatingU16 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: u16) -> Self::Output {
|
||||
SaturatingU16 {
|
||||
value: self.value.saturating_add(rhs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<&u16> for SaturatingU16 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: &u16) -> Self::Output {
|
||||
SaturatingU16 {
|
||||
value: self.value.saturating_add(rhs.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Add<&Self> for SaturatingU16 {
|
||||
type Output = Self;
|
||||
fn add(self, rhs: &Self) -> Self::Output {
|
||||
SaturatingU16 {
|
||||
value: self.value.saturating_add(rhs.value.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for SaturatingU16 {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.value == other.value
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<u16> for SaturatingU16 {
|
||||
fn eq(&self, other: &u16) -> bool {
|
||||
self.value == other.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fn intro() -> &'static str {
|
||||
// TODO: fix me 👇
|
||||
"I'm ready to __!"
|
||||
"I'm ready to refine the `Ticket` type!"
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user