Cannot use inline From and PartialOrd traits for Box object borders

Admittedly, I'm pretty new to Rust, but I like what I see so far. However, I encountered a problem when I receive an error message:

error: only the builtin traits can be used as closure or object bounds [E0225]
defaults: HashMap<String, Box<Any + From<String> + PartialOrd>>,
                                    ^~~~~~~~~~~~

for the following code:

pub struct Builder {                                                                                                                                                                                                                           
    defaults: HashMap<String, Box<Any + From<String> + PartialOrd>>,                                                                                                                                                                           
    ...
}

If I delete the link to From, I get the same error, but for PartialOrd. I do not understand why, because I'm sure that both Fromand PartialOrdare built in features. Any help would be greatly appreciated.

+4
source share
1 answer
$ rustc --explain E0225
You attempted to use multiple types as bounds for a closure or trait object.
Rust does not currently support this. A simple example that causes this error:

fn main() {
    let _: Box<std::io::Read+std::io::Write>;
}

Builtin traits are an exception to this rule: it possible to have bounds of
one non-builtin type, plus any number of builtin types. For example, the
following compiles correctly:

fn main() {
    let _: Box<std::io::Read+Copy+Sync>;
}

PartialOrdand Fromnot built-in, they are defined in the standard library. Type traits Copyand Syncbuilt-in.

, , :

trait MyTrait: Any + From<String> + PartialOrd {}

, ( , ):

impl<T> MyTrait for T where T: Any + From<String> + PartialOrd {}
+7

All Articles