小编blu*_*yll的帖子

如何将(String,String)元组上的迭代器转换为(&str,&str)的迭代器?

我无法从Iterator转换(String, String)为Iterator (&str, &str).我正在使用外部库,因此无法更改其签名,也不确定是否需要.基本上我有这个功能def:

use hyper;

fn build_url<'a, I>(host: &'a str, port: u16, path: &'a str, params: I) -> 
   hyper::Url where I: Iterator<Item=(String, String)> {

       let mut url = hyper::Url::parse(&format!("http://{h}:{p}/{pt}",
                                            h = self.etcd_host,
                                            p = self.etcd_port,
                                            pt = path));
       if let Err(e) = url {
           panic!("error parsing url: {}", e);
       }

       let mut url = url.unwrap();

       // fn set_query_from_pairs<'a, I>(&mut self, pairs: I)
       //  where I: Iterator<Item=(&'a str, &'a str)>
       url.set_query_from_pairs(
            params.map(|x: (String, String)| -> 
                       (&str, &str) …
Run Code Online (Sandbox Code Playgroud)

lifetime rust

3
推荐指数
1
解决办法
794
查看次数

标签 统计

lifetime ×1

rust ×1