-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A sketch of numeric operations and comparison
- Loading branch information
Showing
5 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
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,44 @@ | ||
/// An internal representation of something that can be compared | ||
/// | ||
/// Only numbers and strings can be compared for now. | ||
/// | ||
/// Use `into()` conversion to make the value. | ||
pub struct Comparable<'a>(ComparableInner<'a>); | ||
|
||
enum ComparableInner<'a> { | ||
I64(i64), | ||
U64(u64), | ||
F64(f64), | ||
Str(&'a str), | ||
String(String), | ||
} | ||
|
||
impl<'a> From<i64> for Comparable<'a> { | ||
fn from(x: i64) -> Comparable<'a> { | ||
Comparable(ComparableInner::I64(x)) | ||
} | ||
} | ||
|
||
impl<'a> From<u64> for Comparable<'a> { | ||
fn from(x: u64) -> Comparable<'a> { | ||
Comparable(ComparableInner::U64(x)) | ||
} | ||
} | ||
|
||
impl<'a> From<f64> for Comparable<'a> { | ||
fn from(x: f64) -> Comparable<'a> { | ||
Comparable(ComparableInner::F64(x)) | ||
} | ||
} | ||
|
||
impl<'a> From<&'a str> for Comparable<'a> { | ||
fn from(x: &'a str) -> Comparable<'a> { | ||
Comparable(ComparableInner::Str(x)) | ||
} | ||
} | ||
|
||
impl<'a> From<String> for Comparable<'a> { | ||
fn from(x: String) -> Comparable<'a> { | ||
Comparable(ComparableInner::String(x)) | ||
} | ||
} |
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
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,28 @@ | ||
/// An internal representation of a number that may be integer of real | ||
/// | ||
/// Use `into()` conversion to make the value. | ||
pub struct Number(NumberInner); | ||
|
||
enum NumberInner { | ||
I64(i64), | ||
U64(u64), | ||
F64(f64), | ||
} | ||
|
||
impl From<i64> for Number { | ||
fn from(x: i64) -> Number { | ||
Number(NumberInner::I64(x)) | ||
} | ||
} | ||
|
||
impl From<u64> for Number { | ||
fn from(x: u64) -> Number { | ||
Number(NumberInner::U64(x)) | ||
} | ||
} | ||
|
||
impl From<f64> for Number { | ||
fn from(x: f64) -> Number { | ||
Number(NumberInner::F64(x)) | ||
} | ||
} |
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
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