-
-
Save ddprrt/f46956f76e056e358a3ab29af511f6c0 to your computer and use it in GitHub Desktop.
Launchpad 2 Extra material
This file contains 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
impl Podcast { | |
// ... | |
fn to_html(&self) -> String { | |
format!( | |
r#" | |
<html> | |
<head> | |
<title>My Podcast: {}</title> | |
</head> | |
<body> | |
<h1>{}</h1> | |
<p>{}</p> | |
<audio controls src="{}"></audio> | |
</body> | |
</html> | |
"#, | |
self.title, | |
self.title, | |
self.description, | |
match self.audio_file { | |
Some(ref file) => file, | |
None => "No audio available", | |
} | |
) | |
} | |
} |
This file contains 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
async fn root( | |
State(app_state): State<AppState> | |
) -> impl IntoResponse { | |
let response = format!( | |
r#" | |
<html> | |
<head> | |
<title>My Podcasts</title> | |
</head> | |
<body> | |
<h1>My Podcasts</h1> | |
<ul> | |
{} | |
</ul> | |
</body> | |
</html> | |
"#, | |
app_state | |
.iter() | |
.enumerate() | |
.map(|(id, podcast)| { | |
format!(r#"<li><a href="/{}">{}</a></li>"#, id, podcast.title) | |
}) | |
.collect::<Vec<String>>() | |
.join("\n") | |
); | |
Html(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment