• 1 Post
  • 782 Comments
Joined 3 years ago
cake
Cake day: June 11th, 2023

help-circle


  • On a long enough timeline, neither is Rust probably, but such is the price of innovation.

    It is always so weird to me that people literally seem to believe that complex inventions like programming languages are something we got to perfection within 20 (in C’s case) or 30 (in C++'s case) years of the advent of our industry. Especially considering an iteration cycle is somewhere in the decade or longer range for these. I would expect this to improve for at least a couple of hundred years before we reach the point where nothing new can be added to existing programming languages that is worth starting over with a new language to reap the benefits.




  • Out of all the languages I have ever worked with upgrading dependencies in Rust is literally the easiest. All the times when that was hard in Rust it was hard for reasons that literally affect all languages such as a library that had become unmaintained or a significant API change to an obscure library. The major libraries implementing common functionality are all very well managed and barely ever have breaking changes.





  • Your return will return from the function, not from the for loop as you probably assume. The for loop itself does not return a value. Only loop based loops can use break to return values, other loops do not.

    You also forgot the let keyword in your assignment

    I assume you want to return the value of the href attribute for the first node that has one? In that case you want something like

    fn get_first_href_value(link_nodes: Select) -> Option<String> {
            for node in link_nodes {
                if let Some(href_value) = node.value().attr("href") {
                    return Some(href_value.into());
                }
            }
    
            None
    }
    

    or, more idiomatically

    fn get_first_href_value(link_nodes: Select) -> Option<String> {
        link_nodes.into_iter().find_map(|node| node.value().attr("href")).map(|v| v.to_string())
    }