diff options
author | Radosław Kot <rdkt13@gmail.com> | 2021-07-31 16:59:05 +0200 |
---|---|---|
committer | Radosław Kot <rdkt13@gmail.com> | 2021-10-23 16:58:41 +0200 |
commit | 4775107810cbc7e045f075586e5061ed8aa51398 (patch) | |
tree | 3939a4c5e97fed68efbfc4485218b944b99f4502 /src | |
parent | abe7f7624a02261cde994d5128d44c63fe65dd60 (diff) |
Satisfy clippy's type_complexity lint
Diffstat (limited to 'src')
-rw-r--r-- | src/file/mod.rs | 2 | ||||
-rw-r--r-- | src/file/source/file.rs | 14 | ||||
-rw-r--r-- | src/file/source/mod.rs | 22 | ||||
-rw-r--r-- | src/file/source/string.rs | 19 |
4 files changed, 42 insertions, 15 deletions
diff --git a/src/file/mod.rs b/src/file/mod.rs index 8d5b538..6c1e4c5 100644 --- a/src/file/mod.rs +++ b/src/file/mod.rs @@ -123,7 +123,7 @@ where .resolve(self.format.clone()) .map_err(|err| ConfigError::Foreign(err)) { - Ok((uri, contents, format)) => (uri, contents, format), + Ok(result) => (result.uri, result.content, result.format), Err(error) => { if !self.required { diff --git a/src/file/source/file.rs b/src/file/source/file.rs index 0feb447..e50b200 100644 --- a/src/file/source/file.rs +++ b/src/file/source/file.rs @@ -5,9 +5,9 @@ use std::io::{self, Read}; use std::iter::Iterator; use std::path::{Path, PathBuf}; -use crate::file::format::ALL_EXTENSIONS; -use crate::file::{FileExtensions, FileSource}; -use crate::Format; +use crate::file::{ + format::ALL_EXTENSIONS, source::FileSourceResult, FileExtensions, FileSource, Format, +}; /// Describes a file sourced from a file #[derive(Clone, Debug)] @@ -98,7 +98,7 @@ where fn resolve( &self, format_hint: Option<F>, - ) -> Result<(Option<String>, String, Box<dyn Format>), Box<dyn Error + Send + Sync>> { + ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>> { // Find file let (filename, format) = self.find_file(format_hint)?; @@ -114,7 +114,11 @@ where let mut text = String::new(); file.read_to_string(&mut text)?; - Ok((Some(uri.to_string_lossy().into_owned()), text, format)) + Ok(FileSourceResult { + uri: Some(uri.to_string_lossy().into_owned()), + content: text, + format, + }) } } diff --git a/src/file/source/mod.rs b/src/file/source/mod.rs index 4a8877b..cd37317 100644 --- a/src/file/source/mod.rs +++ b/src/file/source/mod.rs @@ -14,5 +14,25 @@ where fn resolve( &self, format_hint: Option<T>, - ) -> Result<(Option<String>, String, Box<dyn Format>), Box<dyn Error + Send + Sync>>; + ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>>; +} + +pub struct FileSourceResult { + pub(crate) uri: Option<String>, + pub(crate) content: String, + pub(crate) format: Box<dyn Format>, +} + +impl FileSourceResult { + pub fn uri(&self) -> &Option<String> { + &self.uri + } + + pub fn content(&self) -> &str { + self.content.as_str() + } + + pub fn format(&self) -> &dyn Format { + self.format.as_ref() + } } diff --git a/src/file/source/string.rs b/src/file/source/string.rs index 9bec751..700d574 100644 --- a/src/file/source/string.rs +++ b/src/file/source/string.rs @@ -1,7 +1,10 @@ use std::error::Error; -use crate::file::{FileExtensions, FileSource}; -use crate::Format; +use crate::{ + file::source::FileSourceResult, + file::{FileExtensions, FileSource}, + Format, +}; /// Describes a file sourced from a string #[derive(Clone, Debug)] @@ -20,11 +23,11 @@ where fn resolve( &self, format_hint: Option<F>, - ) -> Result<(Option<String>, String, Box<dyn Format>), Box<dyn Error + Send + Sync>> { - Ok(( - None, - self.0.clone(), - Box::new(format_hint.expect("from_str requires a set file format")), - )) + ) -> Result<FileSourceResult, Box<dyn Error + Send + Sync>> { + Ok(FileSourceResult { + uri: None, + content: self.0.clone(), + format: Box::new(format_hint.expect("from_str requires a set file format")), + }) } } |