Hello @hftautobot, and welcome 
-
A few "meta" remarks about the forum and formatting
You can write code or text snippets using triple backquotes (```
) followed by the "syntax highlighting flavor" of your choice on the same line, and then putting the snippet on a new line afterwards, and finally ending the snippet with yet another set of triple backquotes:
```<language>
... snippet ...
... here ...
```
Two main examples:
-
Use text
as the <language>
for no syntax highlighting (e.g., compiler error messages):
```text
error[E0308]: mismatched types
--> src/lib.rs:20:9
|
18 | fn get_value (&mut self, index: usize) -> Option<Self::Item>
| ------------------ expected `Option<f64>` because of return type
19 | {
20 | self.indicator.get_value(index)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `f64`, found associated type
|
= note: expected enum `Option<f64>`
found enum `Option<<T as Indicator>::Item>`
= help: consider constraining the associated type `<T as Indicator>::Item` to `f64`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
```
preview
error[E0308]: mismatched types
--> src/lib.rs:20:9
|
18 | fn get_value (&mut self, index: usize) -> Option<Self::Item>
| ------------------ expected `Option<f64>` because of return type
19 | {
20 | self.indicator.get_value(index)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `f64`, found associated type
|
= note: expected enum `Option<f64>`
found enum `Option<<T as Indicator>::Item>`
= help: consider constraining the associated type `<T as Indicator>::Item` to `f64`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
-
Use rust
(or nothing at all) as the <language>
for Rust syntax highlighting:
```rust
fn main ()
{}
```
preview
fn main ()
{}
Finally, feel free to try to write minimal reproducible code snippets in The Playground; you will have an option on the top right menus to share a link to it.
All of this will make it far easier for users of this forum to understand the issue you are facing, and thus to help you more quickly and with more accurate suggestions / solutions 
Since we are lacking some context, I have inferred that your code may look like:
mod traits {
pub
trait Indicator {
type Item;
fn get_value (&mut self, index: usize) -> Option<Self::Item>
;
}
}
use traits::Indicator;
struct Wrapper<T> {
indicator: T,
}
impl<T : Indicator> Indicator for Wrapper<T> {
type Item = f64;
fn get_value (&mut self, index: usize) -> Option<Self::Item>
{
self.indicator.get_value(index)
}
}
Indeed, the above code yields an error message very similar to yours:
error[E0308]: mismatched types
--> src/lib.rs:21:9
|
19 | fn get_value (&mut self, index: usize) -> Option<Self::Item>
| ------------------ expected `Option<f64>` because of return type
20 | {
21 | self.indicator.get_value(index)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `f64`, found associated type
|
= note: expected enum `Option<f64>`
found enum `Option<<T as Indicator>::Item>`
= help: consider constraining the associated type `<T as Indicator>::Item` to `f64`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
- (The differences between the error messages may be due to different version of Rust being involved).
In that case, the issue is that the Wrapper
has been specified to have an Item
type of f64
, even though its inner Indicator
has no constraits on the return type.
In that case, depending on your needs, there are two ways to solve the compilation error.
-
Either you loosen the requirement that Wrapper
yield f64
s, and instead, let it return the same item type as its wrappeed .indicator: T
:
impl<T : Indicator> Indicator for Wrapper<T> {
- type Item = f64;
+ type Item = T::Item;
fn get_value (&mut self, index: usize) -> Option<Self::Item>
{
self.indicator.get_value(index)
}
}
-
Or you require the wrapped .indicator: T
yield f64
s too:
- impl<T : Indicator> Indicator for Wrapper<T> {
+ impl<T : Indicator<Item = f64>> Indicator for Wrapper<T> {
type Item = f64;
fn get_value (&mut self, index: usize) -> Option<Self::Item>
{
self.indicator.get_value(index)
}
}
-
Note that the above can also be written as:
impl<T> Indicator for Wrapper<T>
where
T : Indicator<Item = f64>,
{
...
}
-
Playground