Refactor
This commit is contained in:
parent
fc165694eb
commit
49dcb4a84e
5 changed files with 268 additions and 897 deletions
28
src/project.rs
Normal file
28
src/project.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use std::{
|
||||
fs, io,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
pub struct Project {
|
||||
path: PathBuf,
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Self> {
|
||||
let path = fs::canonicalize(path)?;
|
||||
let name = path
|
||||
.file_name()
|
||||
.ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Path {:?} has no file name", path),
|
||||
))?
|
||||
.to_str()
|
||||
.ok_or(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Path {:?} is not valid UTF-8", path),
|
||||
))?
|
||||
.to_string();
|
||||
Ok(Self { path, name })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue