Skip to content

Commit

Permalink
FileFactory の実装
Browse files Browse the repository at this point in the history
  • Loading branch information
hayatroid committed Oct 20, 2024
1 parent 0a586cc commit cbebbae
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions judge-control-app/src/custom_file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod traits;

pub mod directory;
pub mod file_factory;
pub mod text_file;
27 changes: 27 additions & 0 deletions judge-control-app/src/custom_file/file_factory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::path::PathBuf;

struct FileFactory {
path: PathBuf,
}

impl super::traits::FileFactory for FileFactory {
fn new(path: std::path::PathBuf) -> anyhow::Result<Self> {
Ok(Self { path })
}
fn create_file<FileType: super::traits::File>(
&self,
uuid: uuid::Uuid,
args: FileType::InitArgs,
) -> anyhow::Result<FileType> {
let path = self.path.join(uuid.to_string());
FileType::new(path, args)
}
fn create_symlink_of<FileType: super::traits::FileLink>(
&self,
uuid: uuid::Uuid,
original: &FileType,
) -> anyhow::Result<FileType> {
let path = self.path.join(uuid.to_string());
original.create_symlink_to(path)
}
}
2 changes: 1 addition & 1 deletion judge-control-app/src/custom_file/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait FileFactory: Sized {
fn new(path: PathBuf) -> Result<Self>;
fn create_file<FileType: File>(&self, uuid: Uuid, args: FileType::InitArgs)
-> Result<FileType>;
fn create_symlink_of<FileType: File>(
fn create_symlink_of<FileType: FileLink>(
&self,
uuid: Uuid,
original: &FileType,
Expand Down

0 comments on commit cbebbae

Please sign in to comment.