git-next/crates/config/src/git_dir.rs

46 lines
977 B
Rust
Raw Normal View History

use std::{ops::Deref, path::PathBuf};
#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
pub struct GitDir(PathBuf);
impl GitDir {
pub fn new(pathbuf: &std::path::Path) -> Self {
Self(pathbuf.to_path_buf())
}
pub const fn pathbuf(&self) -> &PathBuf {
&self.0
}
}
impl Deref for GitDir {
type Target = PathBuf;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::fmt::Display for GitDir {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", &self.0.display())
}
}
impl From<&str> for GitDir {
fn from(value: &str) -> Self {
Self(value.into())
}
}
impl From<&GitDir> for PathBuf {
fn from(value: &GitDir) -> Self {
value.to_path_buf()
}
}
impl From<PathBuf> for GitDir {
fn from(value: PathBuf) -> Self {
Self(value)
}
}
impl From<GitDir> for PathBuf {
fn from(value: GitDir) -> Self {
value.0
}
}