-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b3d8a65
commit 9d22156
Showing
5 changed files
with
130 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use super::Integer16; | ||
use std::ops::Add; | ||
|
||
impl Add for Integer16 { | ||
type Output = Integer16; | ||
fn add(self, other: Integer16) -> Integer16 { | ||
let _self = self.get_num() as u32; | ||
let _other = other.get_num() as u32; | ||
Integer16::Num((_self + _other) as u16) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use super::Integer16; | ||
|
||
/// # Example | ||
/// ```Rust | ||
/// impl Into<Integer16> for u32 { | ||
/// fn into(self) -> Integer16 { | ||
/// Integer16::Num(self as u16) | ||
/// } | ||
/// } | ||
/// ``` | ||
macro_rules! into_integer16_for_ux { | ||
($($t:ty)*) => ($( | ||
impl Into<Integer16> for $t { | ||
fn into(self) -> Integer16 { | ||
Integer16::Num(self as u16) | ||
} | ||
} | ||
)*) | ||
} | ||
|
||
into_integer16_for_ux!{u8 u16 u32 u64 usize} | ||
|
||
/// # Example | ||
/// ```Rust | ||
/// impl Into<Integer16> for i32 { | ||
/// fn into(self) -> Integer16 { | ||
/// let mut _self = 0; | ||
/// if self < 0 { | ||
/// _self = (u16::max_value() as i32 + (self as i16) as i32 + 1) as u16 | ||
/// } else { | ||
/// _self = self as u16 | ||
/// } | ||
/// Integer16::Num(_self) | ||
/// } | ||
/// } | ||
/// ``` | ||
macro_rules! into_integer16_for_ix { | ||
($($t:ty)*) => ($( | ||
impl Into<Integer16> for $t { | ||
fn into(self) -> Integer16 { | ||
let mut _self = 0; | ||
if self < 0 { | ||
_self = (u16::max_value() as i32 + (self as i16) as i32 + 1) as u16 | ||
} else { | ||
_self = self as u16 | ||
} | ||
Integer16::Num(_self) | ||
} | ||
} | ||
)*) | ||
} | ||
|
||
into_integer16_for_ix!{i8 i16 i32 i64 isize} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
mod into; | ||
mod add; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
pub enum Integer16 { | ||
Num(u16), | ||
Null, | ||
} | ||
|
||
impl Integer16 { | ||
fn get_num(&self) -> u16 { | ||
match *self { | ||
Integer16::Num(e) => e, | ||
_ => 0, | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters