I'm trying to use generics but I don't master that topic well enough and I get this error:
error: mismatched types:
expected `book::mdbook::MDBook<R>`,
found `book::mdbook::MDBook<renderer::html_handlebars::HtmlHandlebars>`
(expected type parameter,
found struct `renderer::html_handlebars::HtmlHandlebars`) [E0308]
This is the relevant code
pub struct MDBook<R> where R: Renderer {
title: String,
author: String,
config: BookConfig,
pub content: Vec<BookItem>,
renderer: R,
}
impl<R> MDBook<R> where R: Renderer {
pub fn new(path: &PathBuf) -> Self {
MDBook {
title: String::from(""),
author: String::from(""),
content: vec![],
config: BookConfig::new()
.set_src(path.join("src"))
.set_dest(path.join("book")),
renderer: HtmlHandlebars::new(), // <---- ERROR HERE
}
}
}
The Renderer
trait is empty at the moment and the implementation for HtmlHandlebars
is
pub struct HtmlHandlebars;
impl Renderer for HtmlHandlebars {
}
impl HtmlHandlebars {
pub fn new() -> Self {
HtmlHandlebars
}
}
What am I doing wrong?