This commit is contained in:
Jeremy Soller 2023-10-26 10:15:09 -06:00
parent fc165694eb
commit 49dcb4a84e
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
5 changed files with 268 additions and 897 deletions

28
src/project.rs Normal file
View 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 })
}
}