-
Notifications
You must be signed in to change notification settings - Fork 5
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
4ba1f16
commit 3a6b1aa
Showing
6 changed files
with
65 additions
and
8 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
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
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 @@ | ||
use cosmwasm_schema::cw_serde; | ||
pub use tuples::*; | ||
|
||
#[cw_serde] | ||
pub struct OrderedTuple2<T> { | ||
pub a: T, | ||
pub b: T, | ||
} | ||
|
||
impl<T> Tuple for OrderedTuple2<T> { | ||
fn arity(&self) -> usize { | ||
2 | ||
} | ||
} | ||
|
||
impl<T> Tuple2 for OrderedTuple2<T> { | ||
type Item0 = T; | ||
type Item1 = T; | ||
} | ||
|
||
impl<T: PartialOrd + Clone + PartialOrd + PartialEq> From<(T, T)> for OrderedTuple2<T> { | ||
fn from(pair: (T, T)) -> Self { | ||
Self::new(pair.0, pair.1) | ||
} | ||
} | ||
|
||
impl<T: PartialOrd + Clone + PartialOrd + PartialEq> OrderedTuple2<T> { | ||
pub fn new(a: T, b: T) -> Self { | ||
let mut pair = (a, b); | ||
pair.sort_selection(); | ||
Self { | ||
a: pair.0, | ||
b: pair.1, | ||
} | ||
} | ||
|
||
pub fn other(&self, denom: &T) -> T { | ||
if &self.a == denom { | ||
self.b.clone() | ||
} else { | ||
self.a.clone() | ||
} | ||
} | ||
} |
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