Compiling playground v0.0.1 (/playground)
error[E0225]: only auto traits can be used as additional traits in a trait object
--> src/main.rs:3:44
|
3 | fn add_(&mut self, s: dyn AsRef<str> + Into<String>);
| ---------- ^^^^^^^^^^^^ additional non-auto trait
| |
| first non-auto trait
|
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: AsRef<str> + Into<String> {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
error[E0225]: only auto traits can be used as additional traits in a trait object
--> src/main.rs:14:44
|
14 | fn add_(&mut self, _: dyn AsRef<str> + Into<String>) {}
| ---------- ^^^^^^^^^^^^ additional non-auto trait
| |
| first non-auto trait
|
= help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: AsRef<str> + Into<String> {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>
For more information about this error, try `rustc --explain E0225`.
error: could not compile `playground` due to 2 previous errors
I don't think that matters at all for what it seems like you are doing, but if you must, add a method that takes &str and one that takes String, or only one that takes String.
Each implementation can have one of them call the other, depending on whether they can reuse the allocation or not.
I do not know your use case, but if you want to be efficient (namely: you want to be able to use &str when you need and get String when you want to copy) you need to use Cow.
Alternatively you can device trait that describes how history element is added, and implement it for both &str and String. In future you might want to support something better than just plain string types after all