Compare commits
2 commits
f2315636da
...
425d166517
Author | SHA1 | Date | |
---|---|---|---|
425d166517 | |||
7573c52755 |
4 changed files with 16 additions and 22 deletions
8
justfile
8
justfile
|
@ -1,9 +1,11 @@
|
||||||
build:
|
build:
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
cargo fmt
|
cargo fmt
|
||||||
cargo fmt --check
|
cargo fmt --check
|
||||||
cargo hack --feature-powerset clippy
|
cargo hack clippy
|
||||||
cargo hack --feature-powerset build
|
cargo hack build
|
||||||
cargo hack --feature-powerset test
|
cargo hack test
|
||||||
cargo doc
|
cargo doc
|
||||||
|
|
||||||
install-hooks:
|
install-hooks:
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
use crate::fs::{DirItem, DirItemIterator, Result};
|
use crate::fs::{DirItem, DirItemIterator, Result};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
path::{DirMarker, PathReal},
|
DirHandle, Error, FileHandle, PathHandle,
|
||||||
DirHandle, Error, FileMarker, PathMarker,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl<'base, 'path> DirHandle<'base, 'path> {
|
impl<'base, 'path> DirHandle<'base, 'path> {
|
||||||
|
@ -62,14 +61,10 @@ impl<'base, 'path> DirHandle<'base, 'path> {
|
||||||
Ok(Box::new(DirItemIterator::new(read_dir)))
|
Ok(Box::new(DirItemIterator::new(read_dir)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'base, 'path> TryFrom<PathReal<'base, 'path, PathMarker>>
|
impl<'base, 'path> TryFrom<PathHandle<'base, 'path>> for FileHandle<'base, 'path> {
|
||||||
for PathReal<'base, 'path, FileMarker>
|
|
||||||
{
|
|
||||||
type Error = crate::fs::Error;
|
type Error = crate::fs::Error;
|
||||||
|
|
||||||
fn try_from(
|
fn try_from(path: PathHandle<'base, 'path>) -> std::result::Result<Self, Self::Error> {
|
||||||
path: PathReal<'base, 'path, PathMarker>,
|
|
||||||
) -> std::result::Result<Self, Self::Error> {
|
|
||||||
match path.as_file() {
|
match path.as_file() {
|
||||||
Ok(Some(dir)) => Ok(dir.clone()),
|
Ok(Some(dir)) => Ok(dir.clone()),
|
||||||
Ok(None) => Err(crate::fs::Error::NotADirectory {
|
Ok(None) => Err(crate::fs::Error::NotADirectory {
|
||||||
|
@ -79,14 +74,10 @@ impl<'base, 'path> TryFrom<PathReal<'base, 'path, PathMarker>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'base, 'path> TryFrom<PathReal<'base, 'path, PathMarker>>
|
impl<'base, 'path> TryFrom<PathHandle<'base, 'path>> for DirHandle<'base, 'path> {
|
||||||
for PathReal<'base, 'path, DirMarker>
|
|
||||||
{
|
|
||||||
type Error = crate::fs::Error;
|
type Error = crate::fs::Error;
|
||||||
|
|
||||||
fn try_from(
|
fn try_from(path: PathHandle<'base, 'path>) -> std::result::Result<Self, Self::Error> {
|
||||||
path: PathReal<'base, 'path, PathMarker>,
|
|
||||||
) -> std::result::Result<Self, Self::Error> {
|
|
||||||
match path.as_dir() {
|
match path.as_dir() {
|
||||||
Ok(Some(dir)) => Ok(dir.clone()),
|
Ok(Some(dir)) => Ok(dir.clone()),
|
||||||
Ok(None) => Err(crate::fs::Error::NotADirectory {
|
Ok(None) => Err(crate::fs::Error::NotADirectory {
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
use crate::fs::Result;
|
use crate::fs::Result;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
path::{FileMarker, PathReal},
|
|
||||||
reader::Reader,
|
reader::Reader,
|
||||||
Error, FileHandle,
|
Error, FileHandle,
|
||||||
};
|
};
|
||||||
|
@ -58,7 +57,7 @@ impl<'base, 'path> FileHandle<'base, 'path> {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn copy(&self, dest: &PathReal<'base, 'path, FileMarker>) -> Result<u64> {
|
pub fn copy(&self, dest: &FileHandle<'base, 'path>) -> Result<u64> {
|
||||||
self.check_error()?;
|
self.check_error()?;
|
||||||
std::fs::copy(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
|
std::fs::copy(self.as_pathbuf(), dest.as_pathbuf()).map_err(Error::Io)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ use std::{
|
||||||
|
|
||||||
use crate::fs::{Error, Result};
|
use crate::fs::{Error, Result};
|
||||||
|
|
||||||
|
use super::{DirHandle, FileHandle, PathHandle};
|
||||||
|
|
||||||
/// Marker trait for the type of [PathReal].
|
/// Marker trait for the type of [PathReal].
|
||||||
pub trait PathType {}
|
pub trait PathType {}
|
||||||
|
|
||||||
|
@ -170,7 +172,7 @@ impl<'base, 'path, T: PathType> PathReal<'base, 'path, T> {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_dir(&self) -> Result<Option<PathReal<'base, 'path, DirMarker>>> {
|
pub fn as_dir(&self) -> Result<Option<DirHandle<'base, 'path>>> {
|
||||||
self.check_error()?;
|
self.check_error()?;
|
||||||
if self.as_pathbuf().is_dir() {
|
if self.as_pathbuf().is_dir() {
|
||||||
Ok(Some(PathReal::new(self.base, self.path)))
|
Ok(Some(PathReal::new(self.base, self.path)))
|
||||||
|
@ -193,7 +195,7 @@ impl<'base, 'path, T: PathType> PathReal<'base, 'path, T> {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn as_file(&self) -> Result<Option<PathReal<'base, 'path, FileMarker>>> {
|
pub fn as_file(&self) -> Result<Option<FileHandle<'base, 'path>>> {
|
||||||
self.check_error()?;
|
self.check_error()?;
|
||||||
if self.as_pathbuf().is_file() {
|
if self.as_pathbuf().is_file() {
|
||||||
Ok(Some(PathReal::new(self.base, self.path)))
|
Ok(Some(PathReal::new(self.base, self.path)))
|
||||||
|
@ -202,7 +204,7 @@ impl<'base, 'path, T: PathType> PathReal<'base, 'path, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl From<PathReal<'_, '_, PathMarker>> for PathBuf {
|
impl<'base, 'path> From<PathHandle<'base, 'path>> for PathBuf {
|
||||||
fn from(path: PathReal<PathMarker>) -> Self {
|
fn from(path: PathReal<PathMarker>) -> Self {
|
||||||
path.base.join(path.path)
|
path.base.join(path.path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue