salvo-rs / salvo

A powerful web framework built with a simplified design.
https://salvo.rs
Apache License 2.0
3.31k stars 201 forks source link

请教&mut Request两次读取数据问题 #813

Closed Ants24 closed 3 months ago

Ants24 commented 3 months ago
#[handler]
pub async fn data_source_list(depot: &Depot, rep: &mut Response, req: &mut Request) {
    let filter: DataSourceFilter = req.parse_queries::<DataSourceFilter>().unwrap();
    let page_info = req.parse_queries::<PageInfo>().unwrap();
    match get_data_source_by_page(page_info, filter).await {
}}

我需要读取url中的翻页信息,同时也需要读取查询条件,我分两次读取,但是rust限制

cannot borrow `*req` as mutable more than once at a time second mutable borrow occurs here

如何分两次读取到相应的信息,求教!

chrislearn commented 3 months ago

你的 DataSourceFilterPageInfo 保证里面没有引用的数据类型就好了.

Ants24 commented 3 months ago

你的 DataSourceFilterPageInfo 保证里面没有引用的数据类型就好了. 是有引用的数据类型,有的话,怎么处理?

chrislearn commented 3 months ago

这个如果有 就没得办法啊 Rust 的限制. 除非你第一个引用已经 drop 了.

Ants24 commented 3 months ago

这个如果有 就没得办法啊 Rust 的限制. 除非你第一个引用已经 drop 了.

好的,谢谢!,drop了后面就不能使用了,只能把&str 改成 String了