Hi,
I get the following error:
error[E0308]: mismatched types
--> owo-colors/src/dyn_styles.rs:194:21
|
193 | pub fn apply_to<'a, T>(&self, target: &'a T) -> Styled<&'a T> {
| - this type parameter
194 | Styled::new(target, *self)
| ^^^^^^ expected `&T`, found type parameter `T`
|
= note: expected reference `&&T`
found reference `&'a T`
And I really don't get it.
First, it says 'expected &T
, found type parameter T
' and then it says 'note: expected reference &&T
found reference &'a T
'.
I don't see how there could be any T
, or what would expect &&T
.
I spend already more than an hour to find the reason for this error, so any help is greatly appreciated!
Here is the relevant code:
// Btw., it's correct to derive `Copy` here because it only contains
// `&static str` and `bool` values, or would it still make sense to
// work with references?
#[derive(Default, Copy, Clone)]
pub struct Style {
fg: Option<&'static str>,
bg: Option<&'static str>,
bold: bool,
dimmed: bool,
italic: bool,
underline: bool,
blink: bool,
blink_fast: bool,
reversed: bool,
hidden: bool,
strikethrough: bool,
}
impl Style {
pub fn new() -> Self {
Self::default()
}
pub fn apply_to<'a, T>(&self, target: &'a T) -> Styled<&'a T> {
Styled::new(target, *self)
// ^ This where the error happens
}
/* more code */
}
pub struct Styled<'a, T> {
target: &'a T,
style: Style,
}
impl<'a, T> Styled<'a, T> {
fn new(target: &'a T, style: Style) -> Self {
Self {target, style}
}
}
Let me know if the problem could be somewhere else, and I will publish the code somewhere.