Skip to main content

renamer_rs/processor/
inputs.rs

1use std::fmt::Debug;
2use std::hash::Hash;
3use std::path::{Path, PathBuf};
4
5/// Enum used to pass inputs to the [`ProcessorBuilder`][crate::ProcessorBuilder]
6#[derive(Debug, Eq, PartialEq, Hash)]
7pub enum InputType {
8    /// Represents file path input and contains [`FileInput`]
9    File(FileInput),
10    /// Represents plain text input and contains [`TextInput`]
11    Text(TextInput),
12}
13
14/// Represents file path input in [`InputType`]
15#[derive(Debug, Eq, PartialEq, Hash)]
16pub struct FileInput {
17    value: PathBuf,
18}
19
20/// Represents plain text input in [`InputType`]
21#[derive(Debug, Eq, PartialEq, Hash)]
22pub struct TextInput {
23    value: String,
24}
25
26impl InputType {
27    /// Create a new [`InputType`] of variant [`File`]
28    pub fn new_file<P: AsRef<Path>>(value: P) -> Self {
29        Self::File(FileInput::new(value))
30    }
31
32    /// Create a new [`InputType`] of variant [`Text`]
33    pub fn new_text<S: AsRef<str>>(value: S) -> Self {
34        Self::Text(TextInput::new(value))
35    }
36}
37
38impl FileInput {
39    /// Create a new [`FileInput`]
40    pub fn new<P: AsRef<Path>>(value: P) -> Self {
41        Self {
42            value: value.as_ref().into(),
43        }
44    }
45
46    /// Return value as a [`Path`]
47    pub fn value(&self) -> &Path {
48        &self.value
49    }
50}
51
52impl TextInput {
53    /// Create a new [`TextInput`]
54    pub fn new<S: AsRef<str>>(value: S) -> Self {
55        Self {
56            value: value.as_ref().into(),
57        }
58    }
59
60    /// Return value as a [`str`]
61    pub fn value(&self) -> &str {
62        &self.value
63    }
64}