Created
April 16, 2018 15:53
-
-
Save kevinw/29e2ea3c6e08ac04428015a67e9324f4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <label>{{ todo.subject|linkify|safe }}</label> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Running 'cargo run'] | |
| Compiling homepage v0.1.0 (file:///C:/Users/kevin/src/homepage) | |
| error[E0597]: borrowed value does not live long enough | |
| --> src\view.rs:27:10 | |
| | | |
| 27 | #[derive(Template)] | |
| | ^^^^^^^- | |
| | | | | |
| | | temporary value dropped here while still borrowed | |
| | temporary value does not live long enough | |
| | | |
| = note: values in a scope are dropped in the opposite order they are created | |
| = note: consider using a `let` binding to increase its lifetime | |
| error: aborting due to previous error | |
| For more information about this error, try `rustc --explain E0597`. | |
| error: Could not compile `homepage`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use askama::Template; | |
| mod filters { | |
| pub fn linkify(s: &str) -> ::askama::Result<String> { | |
| let mut finder = ::linkify::LinkFinder::new(); | |
| finder.kinds(&[::linkify::LinkKind::Url]); | |
| let mut last = 0; | |
| let mut result = String::new(); | |
| for link in finder.links(&s) { | |
| result.push_str(&s[last .. link.start()]); | |
| result.push_str(&format!("<a href=\"{}\">{}</a>", link.as_str(), link.as_str())); | |
| last = link.end(); | |
| } | |
| if last == 0 { | |
| result = s.to_string(); | |
| } else { | |
| result.push_str(&s[last ..]); | |
| } | |
| Ok(result) | |
| } | |
| } | |
| #[derive(Template)] | |
| #[template(path = "hello.html")] | |
| struct HelloTemplate<'a> { | |
| /* .. */ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment