#[derive(Debug)]
pub struct nav2_filesys {
pub path : String,
pub mode : nav2_filemode,
pub filetype : nav2_filetype,
options : OpenOptions,
file_handle : Option<File>,
textreader : Option<BufReader<File>>,
}
impl nav2_filesys {
// # new函数,只需添加要读取(写入)文件的路径
pub fn new(filepath : String) -> nav2_filesys {
nav2_filesys {
path : filepath.clone(),
mode : nav2_filemode::reader,
filetype : nav2_filetype::text,
options : OpenOptions::new(),
file_handle : None,
textreader : None,
}
}
// # 设置读取模式
pub fn set_mode(&mut self, mode : nav2_filemode) {
self.mode = mode;
match mode {
nav2_filemode::reader => self.options.read(true),
nav2_filemode::writer => self.options.write(true).create(true),
nav2_filemode::appender => self.options.append(true),
};
}
// # 设置文档编码格式
pub fn set_format(&mut self, format : nav2_filetype) {
self.filetype = format;
// 当读取格式为文本时,需要将File绑定给
if self.filetype == nav2_filetype::text {
}
}
// # 打开文件
pub fn open(&mut self) -> std::io::Result<()> {
self.file_handle = Some(self.options.open(self.path.as_str()));
// match self.mode {
// nav2_filemode::reader => self.options.open(self.path.as_str())?,
// nav2_filemode::writer => self.options.open(self.path.as_str())?,
// nav2_filemode::appender => self.options.open(self.path.as_str())?,
// }
Ok(())
}
// # 读取文本文件的一行
pub fn read_line(&mut self) -> std::io::Result<String> {
Ok(String::new())
}
}
the error messages ars as follows :
error[E0616]: field `options` of struct `io_type::nav2_filesys` is private
--> src/nav2_io_impl.rs:27:47
|
27 | nav2_filemode::reader => self.options.read(true),
| ^^^^^^^ private field
error[E0616]: field `options` of struct `io_type::nav2_filesys` is private
--> src/nav2_io_impl.rs:28:47
|
28 | nav2_filemode::writer => self.options.write(true).create(true),
| ^^^^^^^ private field
error[E0616]: field `options` of struct `io_type::nav2_filesys` is private
--> src/nav2_io_impl.rs:29:49
|
29 | nav2_filemode::appender => self.options.append(true),
| ^^^^^^^ private field
error[E0616]: field `file_handle` of struct `io_type::nav2_filesys` is private
--> src/nav2_io_impl.rs:45:18
|
45 | self.file_handle = Some(self.options.open(self.path.as_str()));
| ^^^^^^^^^^^ private field
error[E0616]: field `options` of struct `io_type::nav2_filesys` is private
--> src/nav2_io_impl.rs:45:42
|
45 | self.file_handle = Some(self.options.open(self.path.as_str()));
| ^^^^^^^ private field
For more information about this error, try `rustc --explain E0616`.
i'm a new rust programer ,thank you very much if could help