@dontblink Looks like there’s some weird stuff between my instance and yours in the formatting. There shouldn’t be any backslashes anywhere
Kielet (languages); englanti (English), suomi, huonoo saksaa (schlechtes Deutsche) Ruoka intoilija, Matemaatikko, koodari, Rust, tekoäly, ulkosuomalainen… hän (finnish only has one 3rd Person singular pronoun (for people) he/him in English) Bannerkuva: “Sickos-Yes” Meemi katso tuottamani Rustin tyyppi virhe. Profiilikuva: anime versio itsestäni
@dontblink Looks like there’s some weird stuff between my instance and yours in the formatting. There shouldn’t be any backslashes anywhere
@dontblink Here’s a little explanation for the methods
- into\_iter
: converts Select
into an iterator (a for loop does this implicitly)
- filter\_map
: takes an iterator and constructs an iterator from an Fn(T) -\> Option\<S\>
where the emitted elements are the elements for which applying the function/closure is Some
- next
: takes the next element of the iterator as an Option
.
@dontblink It’s a little unclear what you want to do. It looks like Select implements into iterator. As far as I can parse your code you want to get the first node with a href element. In that case you should do:
link\_nodes.into\_iter().filter\_map(|node| node.value().attr("href")).map(String::from).next()
@dontblink If you really want to do it in a loop, you could do something like
fn get\_links(link\_nodes: Select) -\> Option\<String\> { let mut rel\_permalink: Option\<String\> = None; for node in link\_nodes { if let Some(link) = node.value().attr("href")? { rel\_permalink = Some(String::from(link)); break } }; rel\_permalink }
That said, your function name suggest you want _all_ links, so some kind of collection of links. Is this the case?