mr_bovo
mr_bovo

Reputation: 19

Increasing the traits requirement for a type in Rust

Suppose I have the following

pub struct A { type M : Eq + PartialOrd; } 

How can I create something like

struct B { type N : Eq + PartialOrd + std::hash::Hash; } 

Without necessarily referencing Eq + PartialOrd but instead reference directly M and write something like

type N = A::M + std::hash::Hash;

Upvotes: 0

Views: 40

Answers (1)

Netwave
Netwave

Reputation: 42796

It is still unstable, but the way of doing this would be trait_alias:

#![feature(trait_alias)]

trait At = Eq + PartialOrd;
trait Bt = At + std::hash::Hash;

Playground

Upvotes: 3

Related Questions