Hey folks, not sure why my brain turns to mush whenever generics get even slightly complex, but it does.
I'm working on voice support in tts-rs. There's currently some non-functional code there which fails to build under Linux, so if anyone would mind checking that out then that's probably the quickest way to figure out what I'm struggling with. Otherwise, I'll link to a few highlights.
My first error is here:
error[E0283]: type annotations needed
--> src/backends/speech_dispatcher.rs:114:18
|
114 | self.stop()?;
| ^^^^ cannot infer type for type parameter `T` declared on the trait `Backend`
|
= note: cannot satisfy `_: VoiceImpl`
note: required by a bound in `Backend::stop`
--> src/lib.rs:214:22
|
214 | pub trait Backend<T: VoiceImpl>: Clone {
| ^^^^^^^^^ required by this bound in `Backend::stop`
...
218 | fn stop(&mut self) -> Result<(), Error>;
| ---- required by a bound in this
Where do I need to specify the missing type there? Interesting that other functions in that impl aren't triggering it.
Next, here:
error[E0277]: a value of type `Vec<Voice<T>>` cannot be built from an iterator over elements of type `Voice<speech_dispatcher::Voice>`
--> src/backends/speech_dispatcher.rs:213:14
|
213 | .collect::<Vec<Voice<T>>>();
| ^^^^^^^ value of type `Vec<Voice<T>>` cannot be built from `std::iter::Iterator<Item=Voice<speech_dispatcher::Voice>>`
|
= help: the trait `FromIterator<Voice<speech_dispatcher::Voice>>` is not implemented for `Vec<Voice<T>>`
note: required by a bound in `collect`
--> /home/nolan/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1741:19
|
1741 | fn collect<B: FromIterator<Self::Item>>(self) -> B
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`
help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement
|
94 | impl<T: VoiceImpl> Backend<T> for SpeechDispatcher where Vec<Voice<T>>: FromIterator<Voice<speech_dispatcher::Voice>> {
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
To be fair, it does offer a hint there, but that does seem a bit ugly. I was hoping I could just box up this type and rely on the impl I added, but either my fundamental design is flawed or I'm missing something obvious.
Thanks for any help.