- It's impossible to describe a type that "implements trait A and may or may not implement trait B"
- It's impossible to be generic over a trait (not a type that implements a trait, the trait itself)
How is this different from just describing a type that only "implements trait A" ?
So, specialization? Or something else? I haven't found a need for specialization. I remember when I came from C++ I had a hard time adjusting to "no specialization, no variadics" but idk I haven't missed it in years.
> - It's impossible to be generic over a trait (not a type that implements a trait, the trait itself)
Not sure I understand.
Basically yes. But that works with dynamic dispatch (trait objects) as well as static dispatch (generics).
> Not sure I understand.
A specific pattern I'd like to be able to represent is:
trait AlgorithmAInputData {
...
}
trait AlgorithmA {
trait InputData = AlgorithmAInputData;
...
}
trait DataStorage<trait AlgorithmA> {
type InputData : Algorithm::InputData;
fn get_input_data() -> InputData;
}
fn compute_algorithm_a<Storage: DataStorage<AlgorithmA>>() {
...
} let block = || {
let my_a = a.clone();
let my_b = b.clone();
let my_c = c.clone();
async move {
// use my_a, my_b, my_c
let value = ...
Ok<success::Type, error::Type>(value)
}
}
And you can't use `if let ... && let ...` (two lets for one if) because it doesn't desugar correctly.It's not just "oh throw a box around it and you're good".
I am clearly missing some context because that code is needlessly complex. Are you just trying to show that you have to clone values that you hold a reference to if you want to move them? Because yes, you do. But your example also needlessly borrows them in the outer closure.
Having written Rust professionally for a number of years, this didn't happen too much. Where it did it was stuff like "yeah you need to Box the thing today", which... did not matter, we just did that and moved on.
> It can ever so slightly give one the impression that the rust community has decided that the language is mature and the only thing missing is faster compile times.
That is generally my feeling about Rust. There are a few areas where I'd like to see things get wrapped up (async traits, which are being actively worked on) but otherwise everything feels like a bonus. In terms of things that made Rust difficult to use, yeah, compile times were probably the number one.