dontblink
Hi, i’m into programming, sexual transmutation and psychedelics!
Debian with GNOME
You could also do: !iPostedOnLemmy
Nextcloud + the app “Photos for Nextcloud”
true, that’s why i’m probably switching to Immich for that, even with caching enabled Nextcloud is more useful for storing than to go and look to old photos. It’s just slow to load the content, could be that my network is already really slow by itself tho.
I would say it’s more an acceptable solution than a real alternative for now.
May i ask why everyone hates JavaScript so much? It’s not ironic it’s a real question, i can’t really get it, is it just because it doesn’t have types? Or there’s more?
Hi! First of all thank you so much for the detailed explanation!
What I’m trying to do is scraping some content.
Yes I’m trying to return all links (maybe in a vector), I have a list of elements (Select
, which actually is scraper::html::Select<'_, '_>
) which contain essentially html nodes selections, and I would like to grab each of them, extract the actual link value (), convert it into an actual
String
and push it firstly into a vector containing all the links and then in an istance of a struct which will contain several datas about the scraped page later.
I was trying to use a for loop because that was the first structure that came to my mind, I’m finding it hard to wrap my head around ownership and error handling with rust, using the if let
construct can be a good idea, and I didn’t consider the use of break
!
I also managed to build the “match version” of what I was trying to achieve:
fn get_links(link_nodes: scraper::html::Select<'_, '_>) -> Vec<String> {
let mut links = vec![];
for node in link_nodes {
match node.value().attr("href") {
Some(link) => {
links.push(link.to_string());
}
None => (),
}
}
dbg!(&links);
links
}
I didn’t understand that I had to return the same type for each of the Option
match arms, I thought enum variants could have different types, so if the Some
match arm returns ()
, also None
has to do the same…
If I try with a simpler example I still cannot understand why I cannot do something like:
enum OperativeSystem {
Linux,
Windows,
Mac,
Unrecognised,
}
let absent_os = OperativeSystem::Unrecognised;
find_os(absent_os);
fn find_os(os: OperativeSystem) -> String {
match os {
debian => {
let answer = "This pc uses Linux";
answer.to_string()
}
windows10home => {
let answer = "This pc uses Windows, unlucky you!";
answer.to_string()
}
ios15 => {
let answer = "This pc uses Mac, I'm really sorry!";
answer.to_string()
}
_ => {
let is_unrecognised = true;
is_unrecognised
}
}
}
match is much more intuitive for a beginner, there’s a lot of stuff which go under the hood with ?
This is a lovely story