Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rust 由于生存期/借用错误,Textfile解析函数无法编译_Rust_Text Parsing_Lifetime_Borrow Checker - Fatal编程技术网

Rust 由于生存期/借用错误,Textfile解析函数无法编译

Rust 由于生存期/借用错误,Textfile解析函数无法编译,rust,text-parsing,lifetime,borrow-checker,Rust,Text Parsing,Lifetime,Borrow Checker,注意。这篇文章最初是一篇包含两个问题的较大文章的一部分(我认为这是一个错误以不同的方式表现出来),但为了遵守网站指南,我将其分为两篇独立的文章,这是第二篇。第一个帖子是 我试图解析一个简单的配置文本文件,它每行包含一个三个单词的条目,如下所示: ITEM name value ITEM name value //etc. 我在这里复制了执行解析(以及随后的编译错误)的函数(和): 使用std::fs::File; 使用std::io::prelude::*; 使用std::io::BufRea

注意。这篇文章最初是一篇包含两个问题的较大文章的一部分(我认为这是一个错误以不同的方式表现出来),但为了遵守网站指南,我将其分为两篇独立的文章,这是第二篇。第一个帖子是

我试图解析一个简单的配置文本文件,它每行包含一个三个单词的条目,如下所示:

ITEM name value
ITEM name value
//etc.
我在这里复制了执行解析(以及随后的编译错误)的函数(和):

使用std::fs::File;
使用std::io::prelude::*;
使用std::io::BufReader;
使用std::path::path;
使用std::collections::HashMap;
fn main(){}
发布fn解析(路径:&path)->config\u结构{
让file=file::open(&path).unwrap();
let reader=BufReader::new(&file);
让line_迭代器=reader.lines();
让mut connection_map=HashMap::new();
让mut target_map=HashMap::new();
对于行对行迭代器{
让line_切片=line.unwrap();
让word_vector:Vec=line_slice.split_whitespace().collect();
如果单词_vector.len()!=3{continue;}
//不匹配语句
连接映射。插入(单词向量[1],单词向量[2]);
}
配置结构{连接:连接映射,目标:目标映射}
}

pub-struct-config_-structA
&str
如果没有存储它所包含的值的东西,它就不能存在。它纯粹是一个引用(因此
&

从文件中读取您得到的
String
s;这些提供了存储空间。但是您正在删除它们,试图只返回字符串

也可以这样想:

pub fn parse(path: &Path) -> config_struct<'???>;
pub-fn-parse(路径:&path)->config\u-struct
pub fn parse(path: &Path) -> config_struct<'???>;