-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tide support #79
Comments
Here is a trait so it is now easier to use template with tide. use renderer::Render;
pub async fn not_found_route(_req: Request<AppState>) -> tide::Result {
let mut res = Response::new(StatusCode::NotFound);
res.render_html(|o| Ok(templates::notfound(o)?))?;
Ok(res)
} pub trait Render {
fn render<Call>(&mut self, call: Call) -> std::io::Result<()>
where
Call: FnOnce(&mut dyn std::io::Write) -> std::io::Result<()>;
fn render_html<Call>(&mut self, call: Call) -> std::io::Result<()>
where
Call: FnOnce(&mut dyn std::io::Write) -> std::io::Result<()>;
}
impl Render for tide::Response {
fn render<Call>(&mut self, call: Call) -> std::io::Result<()>
where
Call: FnOnce(&mut dyn std::io::Write) -> std::io::Result<()>,
{
let mut buf = vec![];
call(&mut buf)?;
self.set_body(buf);
Ok(())
}
fn render_html<Call>(&mut self, call: Call) -> std::io::Result<()>
where
Call: FnOnce(&mut dyn std::io::Write) -> std::io::Result<()>,
{
self.render(call)?;
self.set_content_type(tide::http::mime::HTML);
Ok(())
}
} |
The tide example is extended in #94 While doing that I discovered that tide uses a |
Merged the example in #94 . The rendering traits can still be moved from the example to the feature, but that can wait for another PR. |
Awesome. Thanks for improving this. For now I wouldn't go and add it as a feature since the api for tide is changing quite rapidly. Might be can revisit in the next few months once the api are stable. |
I already did add a |
I'll close this. The minimal feature and example exists, but tide itself has not been updated the last two years, so maybe not the most relevant web framework anymore. |
https://github.com/http-rs/tide
I'm currently doing something like this.
The text was updated successfully, but these errors were encountered: