Enum broot::conf::SerdeFormat
source · pub enum SerdeFormat {
Hjson,
Toml,
}
Expand description
Formats usable for reading configuration files
Variants§
Implementations§
source§impl SerdeFormat
impl SerdeFormat
pub fn key(self) -> &'static str
sourcepub fn from_path(path: &Path) -> Result<Self, ConfError>
pub fn from_path(path: &Path) -> Result<Self, ConfError>
Examples found in repository?
src/conf/format.rs (line 51)
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
pub fn read_file<T>(path: &Path) -> Result<T, ProgramError>
where T: DeserializeOwned
{
let format = Self::from_path(path)?;
let file_content = fs::read_to_string(path)?;
match format {
Self::Hjson => {
deser_hjson::from_str::<T>(&file_content)
.map_err(|e| ProgramError::ConfFile {
path: path.to_string_lossy().to_string(),
details: e.into(),
})
}
Self::Toml => {
toml::from_str::<T>(&file_content)
.map_err(|e| ProgramError::ConfFile {
path: path.to_string_lossy().to_string(),
details: e.into(),
})
}
}
}
sourcepub fn read_file<T>(path: &Path) -> Result<T, ProgramError>where
T: DeserializeOwned,
pub fn read_file<T>(path: &Path) -> Result<T, ProgramError>where
T: DeserializeOwned,
Examples found in repository?
src/conf/conf.rs (line 170)
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
pub fn read_file(
&mut self,
path: PathBuf,
) -> Result<(), ProgramError> {
debug!("reading conf file: {:?}", &path);
let mut conf: Conf = SerdeFormat::read_file(&path)?;
overwrite!(self, default_flags, conf);
overwrite!(self, date_time_format, conf);
overwrite!(self, icon_theme, conf);
overwrite!(self, syntax_theme, conf);
overwrite!(self, disable_mouse_capture, conf);
overwrite!(self, capture_mouse, conf);
overwrite!(self, true_colors, conf);
overwrite!(self, show_selection_mark, conf);
overwrite!(self, cols_order, conf);
overwrite!(self, skin, conf);
overwrite!(self, search_modes, conf);
overwrite!(self, max_panels_count, conf);
overwrite!(self, modal, conf);
overwrite!(self, quit_on_last_cancel, conf);
overwrite!(self, file_sum_threads_count, conf);
overwrite!(self, max_staged_count, conf);
overwrite!(self, show_matching_characters_on_path_searches, conf);
overwrite!(self, content_search_max_file_size, conf);
self.verbs.append(&mut conf.verbs);
// the following maps are "additive": we can add entries from several
// config files and they still make sense
overwrite_map!(self, special_paths, conf);
overwrite_map!(self, ext_colors, conf);
self.files.push(path);
// read the imports
for import in &conf.imports {
let file = import.file();
if !import.applies() {
debug!("skipping not applying conf file : {:?}", file);
continue;
}
let import_path = self.solve_conf_path(file)
.ok_or_else(|| ConfError::ImportNotFound { path: file.to_string() })?;
if self.files.contains(&import_path) {
debug!("skipping import already read: {:?}", import_path);
continue;
}
self.read_file(import_path)?;
}
Ok(())
}
Trait Implementations§
source§impl Clone for SerdeFormat
impl Clone for SerdeFormat
source§fn clone(&self) -> SerdeFormat
fn clone(&self) -> SerdeFormat
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for SerdeFormat
impl Debug for SerdeFormat
source§impl Default for SerdeFormat
impl Default for SerdeFormat
source§impl PartialEq<SerdeFormat> for SerdeFormat
impl PartialEq<SerdeFormat> for SerdeFormat
source§fn eq(&self, other: &SerdeFormat) -> bool
fn eq(&self, other: &SerdeFormat) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for SerdeFormat
impl Eq for SerdeFormat
impl StructuralEq for SerdeFormat
impl StructuralPartialEq for SerdeFormat
Auto Trait Implementations§
impl RefUnwindSafe for SerdeFormat
impl Send for SerdeFormat
impl Sync for SerdeFormat
impl Unpin for SerdeFormat
impl UnwindSafe for SerdeFormat
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
impl<R, P> ReadPrimitive<R> for Pwhere
R: Read + ReadEndian<P>,
P: Default,
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian()
.