Welcome to Rust user forum! Great to see conda people here 
Let's fix the errors step by step using compiler helpful suggestions as follows:
Step 1: If you look closer, compiler is suggesting another thing
impl<T: std::cmp::PartialOrd> VersionPart<T> for DefaultPart<T>
Step 2: Adding it shows another error:
--> src/lib.rs:27:39
|
27 | self._value.partial_cmp(other.into())
| ^^^^ the trait `std::convert::From<T>` is not implemented for `&T`
|
= help: the following implementations were found:
<T as std::convert::From<T>>
= note: required because of the requirements on the impl of `std::convert::Into<&T>` for `T`
so a fix can be to remove other.into()
and make it &other
.
Step 3: Making the above changes points to another error:
error[E0599]: no method named `compare_priority` found for type `&DefaultPart<T>` in the current scope
--> src/lib.rs:38:15
|
38 | (self.compare_priority(other.priority()) == Some(Ordering::Equal)) &&
| ^^^^^^^^^^^^^^^^
|
= note: the method `compare_priority` exists but the following trait bounds were not satisfied:
`DefaultPart<T> : VersionPart<_>`
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `compare_priority`, perhaps you need to implement it:
candidate #1: `VersionPart`
then you might say how come? because we've implemented
impl<T: PartialOrd> VersionPart<T> for DefaultPart<T>
however, pay attention to the added bound T: PartialOrd
which needs to be reflected to
impl<T, U> PartialEq<DefaultPart<U>> for DefaultPart<T>
where
T: std::convert::From<U>,
T: PartialEq,
U: PartialEq
Note that pub trait PartialOrd<Rhs = Self>: PartialEq<Rhs>
i.e. a subtrait of PartialEq
so
Step 4: making T: PartialOrd
and U: PartialOrd
points to another error:
error[E0277]: can't compare `T` with `T`
--> src/lib.rs:13:17
|
13 | #[derive(Debug, Eq, Ord)]
| ^^ no implementation for `T < T` and `T > T`
|
= help: the trait `std::cmp::PartialOrd` is not implemented for `T`
= help: consider adding a `where T: std::cmp::PartialOrd` bound
= note: required because of the requirements on the impl of `std::cmp::PartialEq` for `DefaultPart<T>`
So we need to remove the derived Eq
and Ord
mainly because as doc says:
Implementations of PartialEq
, PartialOrd
, and Ord
must agree with each other. It's easy to accidentally make them disagree by deriving some of the traits and manually implementing others.
Step 5: Compiling again points to the last error which is
error[E0507]: cannot move out of `self._value` which is behind a shared reference
--> src/lib.rs:22:27
|
22 | fn value(&self) -> T {self._value.into()}
| ^^^^^^^^^^^ move occurs because `self._value` has type `T`, which does not implement the `Copy` trait
The error says it all, you're moving an internal value from a shared reference &self
without specifying T: Copy
. A fix can be to add the more generate trait Clone
(where Copy: Clone
)
to make the code compile successfully.
However, since you have made all the fields of your struct private, then writing functions like
pub fn EpochPart<'a>(v: i32) -> DefaultPart<i32> {DefaultPart{_priority: 0, _value: v }}
results into leak of private parts
error[E0446]: private type `DefaultPart<i32>` in public interface
--> src/lib.rs:63:1
|
14 | struct DefaultPart<T: Clone> {
| - `DefaultPart<i32>` declared as private
...
63 | pub fn EpochPart<'a>(v: i32) -> DefaultPart<i32> {DefaultPart{_priority: 0, _value: v }}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
So you'd need to make them public explicitly like
pub struct DefaultPart<T: Clone> {
pub _priority: i8,
pub _value: T,
}
however, in standard lint, _
implies a private field, so it'd better to remove _
from the fields
pub struct DefaultPart<T: Clone> {
pub priority: i8,
pub value: T,
}
The final last linting fix is that functions in Rust are snake_case
which I leave them to you.