Skip to content

Commit

Permalink
chore: accept path AsRef<Path> (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop authored Nov 7, 2024
1 parent fe53956 commit 55f52de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions workspace/gh-workflow/src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::error::{Error, Result};
use crate::Workflow;

pub struct Generate {
workflow: Workflow,
path: String,
path: PathBuf,
}

impl Generate {
pub fn new<P: ToString>(workflow: Workflow, path: P) -> Self {
Self { workflow, path: path.to_string() }
pub fn new<P: AsRef<Path>>(workflow: Workflow, path: P) -> Self {
Self { workflow, path: path.as_ref().to_path_buf() }
}

pub fn generate(&self) -> Result<()> {
let comment = include_str!("./comment.yml");
let path = Path::new(self.path.as_str());
let path = self.path.as_path();

path.parent()
.map_or(Ok(()), std::fs::create_dir_all)
Expand Down
3 changes: 2 additions & 1 deletion workspace/gh-workflow/src/workflow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::needless_update)]

use std::fmt::Display;
use std::path::Path;

use derive_setters::Setters;
use indexmap::IndexMap;
Expand Down Expand Up @@ -71,7 +72,7 @@ impl Workflow {
Ok(serde_yaml::from_str(yml)?)
}

pub fn generate<T: ToString>(self, path: T) -> Result<()> {
pub fn generate<T: AsRef<Path>>(self, path: T) -> Result<()> {
Generate::new(self, path).generate()
}

Expand Down

0 comments on commit 55f52de

Please sign in to comment.