gpt4 book ai didi

rust - 在此语句结束时释放临时值

转载 作者:行者123 更新时间:2023-11-29 07:47:47 26 4
gpt4 key购买 nike

我正在尝试使用 Select crate 抓取网页:

let document = Document::from_read(response).unwrap();

for node in document.find(Class("lia-list-row")) {
let title = node.find(Class("page-link")).next().unwrap();
let title_text = title.text().trim();

println!("{}\n", title_text);
}

导致以下错误:

let title_text = title.text().trim();
^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
creates a temporary which is freed while still in use

println!("{} - {}\n", i, title_text);
---------- borrow used here, in later iteration of loop

我通过分离 .text().trim() 解决了这个问题

let title_text = title.text();
let trim_text = title_text.trim();

有什么区别?为什么第一次尝试失败了?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com