Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 21, 2019 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rust-play/dc5b15ac3111e21ebdcf09d8a290df3e to your computer and use it in GitHub Desktop.
Save rust-play/dc5b15ac3111e21ebdcf09d8a290df3e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
let link = (try {
let name = s.stream.get("channel")?.get("name")?.as_str()?;
(try {
let url = format!("https://twitch.tv/{}", name)
.parse::<typed_html::types::Uri>().ok()?;
html!(<a href={url}>{ text!(name) }</a>):
Box<elements::FlowContent<String>>
}: Option<Box<elements::FlowContent<String>>>)
.unwrap_or_else(|| Box::new(dom::TextNode::new(name)))
}: Option<Box<elements::FlowContent<String>>>)
.unwrap_or_else(|| html!("<name missing?>"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment