zellij_utils/plugin_api/
file.rs1pub use super::generated_api::api::file::File as ProtobufFile;
2use crate::data::FileToOpen;
3
4use std::convert::TryFrom;
5use std::path::PathBuf;
6
7impl TryFrom<ProtobufFile> for FileToOpen {
8 type Error = &'static str;
9 fn try_from(protobuf_file: ProtobufFile) -> Result<Self, &'static str> {
10 let path = PathBuf::from(protobuf_file.path);
11 let line_number = protobuf_file.line_number.map(|l| l as usize);
12 let cwd = protobuf_file.cwd.map(|c| PathBuf::from(c));
13 Ok(FileToOpen {
14 path,
15 line_number,
16 cwd,
17 })
18 }
19}
20
21impl TryFrom<FileToOpen> for ProtobufFile {
22 type Error = &'static str;
23 fn try_from(file_to_open: FileToOpen) -> Result<Self, &'static str> {
24 Ok(ProtobufFile {
25 path: file_to_open.path.display().to_string(),
26 line_number: file_to_open.line_number.map(|l| l as i32),
27 cwd: file_to_open.cwd.map(|c| c.display().to_string()),
28 })
29 }
30}