Trait MyTrait

Source
pub trait MyTrait<'a>: Ord {
    type Owned;

    // Required methods
    fn into_owned(self) -> Self::Owned;
    fn clone_onto(&self, other: &mut Self::Owned);
    fn compare(&self, other: &Self::Owned) -> Ordering;
    fn borrow_as(other: &'a Self::Owned) -> Self;

    // Provided methods
    fn less_equals(&self, other: &Self::Owned) -> bool { ... }
    fn equals(&self, other: &Self::Owned) -> bool { ... }
    fn less_than(&self, other: &Self::Owned) -> bool { ... }
}
Expand description

A type that may be converted into and compared with another type.

The type must also be comparable with itself, and follow the same order as if converting instances to T and comparing the results.

Required Associated Types§

Source

type Owned

Owned type into which this type can be converted.

Required Methods§

Source

fn into_owned(self) -> Self::Owned

Conversion from an instance of this type to the owned type.

Source

fn clone_onto(&self, other: &mut Self::Owned)

Source

fn compare(&self, other: &Self::Owned) -> Ordering

Indicates that self <= other; used for sorting.

Source

fn borrow_as(other: &'a Self::Owned) -> Self

Borrows an owned instance as onesself.

Provided Methods§

Source

fn less_equals(&self, other: &Self::Owned) -> bool

self <= other

Source

fn equals(&self, other: &Self::Owned) -> bool

self == other

Source

fn less_than(&self, other: &Self::Owned) -> bool

self < other

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T: Ord + ToOwned + ?Sized> MyTrait<'a> for &'a T

Source§

type Owned = <T as ToOwned>::Owned

Source§

fn into_owned(self) -> Self::Owned

Source§

fn clone_onto(&self, other: &mut Self::Owned)

Source§

fn compare(&self, other: &Self::Owned) -> Ordering

Source§

fn borrow_as(other: &'a Self::Owned) -> Self

Implementors§

Source§

impl<'a, B: Ord + Clone> MyTrait<'a> for Greetings<'a, B>

Source§

type Owned = Vec<B>