• 8 Posts
  • 423 Comments
Joined 1 year ago
cake
Cake day: November 24th, 2023

help-circle


  • It’s quite simple. Just remove the permalink field! If you are calculating it then no need to store it in the struct.

    If you do need the field to be there (ex you serialise it with serde), then create a method called new that takes everything but the permalink, construct your permalink there, then return a new object.

    Your permalink method can now just be self.permalink.to_string()

    P.S. in the second case I’d recommend to change the return type of self.permalink() to &str. It avoids unnecessary cloning of the string.






  • I wouldn’t mind having a explanation of what you want to do instead of the code. It’s not quite clear what you mean.

    Anyways, what you want is to transform an iterator (your Select) into an iterator of Option<String>?

    For that, there’s multiple ways but here’s the simplest:

    link_nodes.map(|node| node.value().attr("href").to_string())

    Essentially, for each elements, we execute a closure (arrow function in JavaScript) that transform the node into your href string.

    P.S. can’t guarantee it works, I don’t know what this “Select” type is, and I’m programming on mobile