diff options
author | Toby Vincent <tobyv13@gmail.com> | 2022-11-20 18:05:06 -0600 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2022-11-20 18:05:06 -0600 |
commit | fe92d86fbe5f73bc2662a128b6431ec2089d05b8 (patch) | |
tree | 8301319ece23fad3142f4b9af196cce2780936b9 /src/paths | |
parent | b1438bd27d32e4e2530825026cc39a8ac5456f68 (diff) |
refactor: remove unnecessary exports
Diffstat (limited to 'src/paths')
-rw-r--r-- | src/paths/config.rs | 61 | ||||
-rw-r--r-- | src/paths/path_entry.rs | 59 |
2 files changed, 61 insertions, 59 deletions
diff --git a/src/paths/config.rs b/src/paths/config.rs index e5af2dc..1e9bc65 100644 --- a/src/paths/config.rs +++ b/src/paths/config.rs @@ -1,6 +1,6 @@ +use super::PathEntry; use figment::{providers::Serialized, value, Figment, Metadata, Profile, Provider}; -use serde::{Deserialize, Deserializer, Serialize}; -use std::{convert::Infallible, path::PathBuf, str::FromStr}; +use serde::{Deserialize, Serialize}; #[derive(Debug, PartialEq, Eq, Clone, Default, Serialize, Deserialize)] pub struct Config { @@ -29,63 +29,6 @@ impl Provider for Config { } } -#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize)] -pub struct PathEntry { - pub path: PathBuf, - pub hidden: bool, - pub recurse: Option<usize>, -} - -impl From<PathBuf> for PathEntry { - fn from(path: PathBuf) -> Self { - Self { - path, - ..Default::default() - } - } -} - -impl FromStr for PathEntry { - type Err = Infallible; - - fn from_str(s: &str) -> Result<Self, Self::Err> { - s.parse().map(PathBuf::into) - } -} - -impl<'de> Deserialize<'de> for PathEntry { - fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(untagged)] - enum Variants { - String(String), - Struct { - path: PathBuf, - #[serde(default)] - hidden: bool, - #[serde(default)] - recurse: Option<usize>, - }, - } - - match Variants::deserialize(deserializer)? { - Variants::String(s) => s.parse().map_err(serde::de::Error::custom), - Variants::Struct { - path, - hidden, - recurse, - } => Ok(Self { - path, - hidden, - recurse, - }), - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/paths/path_entry.rs b/src/paths/path_entry.rs new file mode 100644 index 0000000..b050009 --- /dev/null +++ b/src/paths/path_entry.rs @@ -0,0 +1,59 @@ +use serde::{Deserialize, Deserializer, Serialize}; +use std::{convert::Infallible, path::PathBuf, str::FromStr}; + +#[derive(Debug, PartialEq, Eq, Clone, Default, Serialize)] +pub struct PathEntry { + pub path: PathBuf, + pub hidden: bool, + pub recurse: Option<usize>, +} + +impl From<PathBuf> for PathEntry { + fn from(path: PathBuf) -> Self { + Self { + path, + ..Default::default() + } + } +} + +impl FromStr for PathEntry { + type Err = Infallible; + + fn from_str(s: &str) -> Result<Self, Self::Err> { + s.parse().map(PathBuf::into) + } +} + +impl<'de> Deserialize<'de> for PathEntry { + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> + where + D: Deserializer<'de>, + { + #[derive(Deserialize)] + #[serde(untagged)] + enum Variants { + String(String), + Struct { + path: PathBuf, + #[serde(default)] + hidden: bool, + #[serde(default)] + recurse: Option<usize>, + }, + } + + match Variants::deserialize(deserializer)? { + Variants::String(s) => s.parse().map_err(serde::de::Error::custom), + Variants::Struct { + path, + hidden, + recurse, + } => Ok(Self { + path, + hidden, + recurse, + }), + } + } +} |