These are chat archives for rust-lang/rust
bspeiceI tried annotating the function with
#[cfg(release)], but it's not showing up in
cargo test --release
test events::desc::tests::test_disabled_desc ... error: process didn't exit successfully: `/home/sylwek/projects/rust_lern/ds/target/debug/deps/ds-b10100af7decf363 --nocapture --test-threads=1` (signal: 11, SIGSEGV: invalid memory reference)
waitwhich causes execution to pause and do nothing?
I am trying to extract meta values of a webpage and need some help with understanding the compile error ‘borrowed value does not live long enough’
For a given webpage, scrape values of description and referrer HTML meta fields, and store the key/values in a hashmap.
I am able to print the names and values of description and referrer meta fields. However, when I try to store the name/values in a hash map, I get a compile error ‘borrowed value does not live long enough’
The working code that prints the names/values:
However, I get the compile error if I uncomment the line # 33 - which puts the names and values in the hashmap. I think it is because I am trying to store reference values in the hashmap, but I am unable to connect the lifetimes of the values in the hashmap with the lifetime of parsed_html variable.
Could someone pls explain how to work around this?
let parsed_htmlbecause it has to outlive the thing that uses it.
let mut relevant_meta_name_valuesafter
let all_meta_elements_found, because it contains references to it.
From the compiler error:
= note: values in a scope are dropped in the opposite order they are created
hi @IslandUsurper that fixed it.
I never thought of it from that perspective. I was caught in lifetimes relating to the scope of the function and of the loop. Simply moving
let mut relevant_meta_name_values after
let parsed_html made it work, even though they are in the same ‘main’ scope.