#[derive(Clone, Debug)]
pub struct StoragePath {
path: String,
base_len: usize,
file_separator: char,
}
impl StoragePath {
pub unsafe fn new<S>(path: S, base_len: usize, file_separator: char) -> Self
where
S: Into<String>,
{
let path: String = path.into();
debug_assert!(path.is_char_boundary(base_len));
Self {
path,
base_len,
file_separator,
}
}
}
impl StoragePath {
pub fn path(&self) -> &str {
self.path.as_str()
}
pub unsafe fn path_mut(&mut self) -> &mut String {
&mut self.path
}
pub fn base_len(&self) -> usize {
self.base_len
}
pub fn file_separator(&self) -> char {
self.file_separator
}
}
#[cfg(test)]
mod tests {
use crate::StoragePath;
#[test]
fn properties() {
let mut path: StoragePath = unsafe { StoragePath::new("/the/path", 1, '/') };
assert_eq!(path.path(), "/the/path");
unsafe {
assert_eq!(path.path_mut(), "/the/path");
}
assert_eq!(path.base_len(), 1);
assert_eq!(path.file_separator(), '/');
}
}