fn collect_attrs(attrs: &[(&str, &str)]) -> HashMap<String, String> {
            attrs
                .iter()
                .map(|(a, b)| (a.to_string(), b.to_string()))
                .collect()
        }
to_string 和 to_owned 不是等价的吗?
	    
	    
		1
	    
	    
	    共 4 条评论, 1 页
	
	
    
评论区
写评论原来如此,学到了,谢谢
对以下内容的回复:
.map(|(a, b)| (a.to_owned().to_owned(), b.to_owned().to_owned()))
把转换代码都去掉
(a, b), 你会发现 a/b 的类型是 &&str.&&str.to_owned()类型为&str&&str.to_string()类型为String, 原因是 ToString 会自动解引用.提示什么