You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am implementing typed semver for Rust, and in the course of doing so I wanted to basically add code that can compare an (Unsigned, Unsigned, Unsigned) with another (Unsigned, Unsigned, Unsigned). When I went to implement this though, I noticed that the built in is_greater_or_equal function calls Self::compare::<Internal>. Luckily that wasn't a dealbreaker, but also found that the trait IsEqualPrivate is needed as a constraint on the numbers. That type is already exported, but the private.rs file does say to mention if a use case is found for any of the private code.
Unfortunately I needed to fork IsGreaterOrEqual and change the return value to bool in order to get it to work. Still not totally sure on why all the things I tried did not work, but it at least seems to have something to do with the Internal enum not being published. Below is the code I came up with; it's a minimal test case that implements the code I was mentioning. The full version would have the single (Unsigned) replaced with basically a 3-tuple of Unsigneds.
pub trait IsGreaterOrEqual<Rhs = Self> {
/// The type representing either `True` or `False`
type Output: Bit;
/// Method returning `True` or `False`.
fn is_greater_or_equal(self, rhs: Rhs) -> bool;
}
impl<X1, Y1> IsGreaterOrEqual<(Y1)> for (X1)
where
X1: Unsigned + Cmp<Y1> + typenum::private::IsEqualPrivate<Y1, <X1 as typenum::Cmp<Y1>>::Output>,
Y1: Unsigned,
{
type Output = <X1 as typenum::IsEqual<Y1>>::Output;
fn is_greater_or_equal(self, rhs: (Y1)) -> bool {
<Self::Output as Bit>::to_bool()
}
}
Note that as the code is written in typenum, the return value of is_greater_or_equal is not bool but instead Self::Output, which I was not able to get to compile in my own program.
The text was updated successfully, but these errors were encountered:
It makes sense that you'd need the private trait to implement your own IsGreaterOrEqual, but it surprises me that you'd need to. Do you have an example of where typenum's IsGreaterOrEqual didn't work for you? I may be able to help with that.
Hi there,
I am implementing typed semver for Rust, and in the course of doing so I wanted to basically add code that can compare an
(Unsigned, Unsigned, Unsigned)
with another(Unsigned, Unsigned, Unsigned)
. When I went to implement this though, I noticed that the built inis_greater_or_equal
function callsSelf::compare::<Internal>
. Luckily that wasn't a dealbreaker, but also found that the traitIsEqualPrivate
is needed as a constraint on the numbers. That type is already exported, but the private.rs file does say to mention if a use case is found for any of the private code.Unfortunately I needed to fork IsGreaterOrEqual and change the return value to
bool
in order to get it to work. Still not totally sure on why all the things I tried did not work, but it at least seems to have something to do with theInternal
enum not being published. Below is the code I came up with; it's a minimal test case that implements the code I was mentioning. The full version would have the single(Unsigned)
replaced with basically a 3-tuple ofUnsigned
s.Note that as the code is written in typenum, the return value of
is_greater_or_equal
is notbool
but insteadSelf::Output
, which I was not able to get to compile in my own program.The text was updated successfully, but these errors were encountered: