Skip to content

Commit

Permalink
Rename to cfgfifo
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Oct 30, 2023
1 parent 0070d26 commit dbaf882
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "cfgurate"
name = "cfgfifo"
version = "0.1.0-dev"
edition = "2021"
rust-version = "1.67"
description = "(De)serialize common configuration file formats based on file extension"
authors = ["John Thorvald Wodder II <cfgurate@varonathe.org>"]
repository = "https://github.com/jwodder/cfgurate"
authors = ["John Thorvald Wodder II <cfgfifo@varonathe.org>"]
repository = "https://github.com/jwodder/cfgfifo"
license = "MIT"
keywords = [
"configuration",
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
[![CI Status](https://github.com/jwodder/cfgurate/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/cfgurate/actions/workflows/test.yml)
[![codecov.io](https://codecov.io/gh/jwodder/cfgurate/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/cfgurate)
[![CI Status](https://github.com/jwodder/cfgfifo/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/cfgfifo/actions/workflows/test.yml)
[![codecov.io](https://codecov.io/gh/jwodder/cfgfifo/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/cfgfifo)
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org)
[![MIT License](https://img.shields.io/github/license/jwodder/cfgurate.svg)](https://opensource.org/licenses/MIT)
[![MIT License](https://img.shields.io/github/license/jwodder/cfgfifo.svg)](https://opensource.org/licenses/MIT)

[GitHub](https://github.com/jwodder/cfgurate) | [Issues](https://github.com/jwodder/cfgurate/issues)
[GitHub](https://github.com/jwodder/cfgfifo) | [Issues](https://github.com/jwodder/cfgfifo/issues)

`cfgurate` is a Rust library for serializing & deserializing various common
`cfgfifo` is a Rust library for serializing & deserializing various common
configuration file formats ([JSON][], [JSON5][], [RON][], [TOML][], and
[YAML][]), including autodetecting the format of a file based on its file
extension. It's good for application authors who want to support multiple
configuration file formats but don't want to write out a bunch of boilerplate.
`cfgurate` has already written that boilerplate for you, so let it
(de)serialize your files!
`cfgfifo` has already written that boilerplate for you, so let it (de)serialize
your files!

[JSON]: https://www.json.org
[JSON5]: https://json5.org
Expand Down Expand Up @@ -48,9 +48,9 @@ fn main() -> anyhow::Result<()> {
let Some(cfgpath) = std::env::args().nth(1) else {
anyhow::bail!("No configuration file specified");
};
// cfgurate identifies the format used by the file `cfgpath` based on its
// cfgfifo identifies the format used by the file `cfgpath` based on its
// file extension and deserializes it appropriately:
let cfg: AppConfig = cfgurate::load(cfgpath)?;
let cfg: AppConfig = cfgfifo::load(cfgpath)?;
println!("You specified the following configuration:");
println!("{cfg:#?}");
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/appconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn main() -> anyhow::Result<()> {
let Some(cfgpath) = std::env::args().nth(1) else {
anyhow::bail!("No configuration file specified");
};
// cfgurate identifies the format used by the file `cfgpath` based on its
// cfgfifo identifies the format used by the file `cfgpath` based on its
// file extension and deserializes it appropriately:
let cfg: AppConfig = cfgurate::load(cfgpath)?;
let cfg: AppConfig = cfgfifo::load(cfgpath)?;
println!("You specified the following configuration:");
println!("{cfg:#?}");
Ok(())
Expand Down
90 changes: 45 additions & 45 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
//! `cfgurate` is a Rust library for serializing & deserializing various common
//! `cfgfifo` is a Rust library for serializing & deserializing various common
//! configuration file formats ([JSON][], [JSON5][], [RON][], [TOML][], and
//! [YAML][]), including autodetecting the format of a file based on its file
//! extension. It's good for application authors who want to support multiple
//! configuration file formats but don't want to write out a bunch of
//! boilerplate. `cfgurate` has already written that boilerplate for you, so
//! boilerplate. `cfgfifo` has already written that boilerplate for you, so
//! let it (de)serialize your files!
//!
//! [JSON]: https://www.json.org
Expand All @@ -24,8 +24,8 @@
//! to it. The file's format will be determined based on its file extension.
//!
//! - For finer control over how file formats are identified, configure a
//! [`Cfgurate`] struct and use its [`load()`][Cfgurate::load] and
//! [`dump()`][Cfgurate::dump] methods.
//! [`Cfgfifo`] struct and use its [`load()`][Cfgfifo::load] and
//! [`dump()`][Cfgfifo::dump] methods.
//!
//! - For per-format operations, including (de)serializing to & from strings,
//! readers, and writers, use the [`Format`] enum.
Expand Down Expand Up @@ -88,9 +88,9 @@
//! let Some(cfgpath) = std::env::args().nth(1) else {
//! anyhow::bail!("No configuration file specified");
//! };
//! // cfgurate identifies the format used by the file `cfgpath` based on its
//! // cfgfifo identifies the format used by the file `cfgpath` based on its
//! // file extension and deserializes it appropriately:
//! let cfg: AppConfig = cfgurate::load(cfgpath)?;
//! let cfg: AppConfig = cfgfifo::load(cfgpath)?;
//! println!("You specified the following configuration:");
//! println!("{cfg:#?}");
//! Ok(())
Expand All @@ -107,10 +107,10 @@ use thiserror::Error;
#[cfg(feature = "ron")]
use ron::ser::PrettyConfig;

/// An enum of file formats supported by this build of `cfgurate`.
/// An enum of file formats supported by this build of `cfgfifo`.
///
/// Each variant is only present if the corresponding Cargo feature of
/// `cfgurate` was enabled at compile time.
/// `cfgfifo` was enabled at compile time.
///
/// A Format can be [displayed][std::fmt::Display] as a string containing its
/// name in all-uppercase, and a Format can be [parsed][std::str::FromStr] from
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Format {
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"use cfgfifo::Format;\n",
"\n",
"assert_eq!(Format::Json.extensions(), &[\"json\"]);\n",
"assert_eq!(Format::Yaml.extensions(), &[\"yaml\", \"yml\"]);\n",
Expand Down Expand Up @@ -208,7 +208,7 @@ impl Format {
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"use cfgfifo::Format;\n",
"\n",
"assert!(Format::Json.has_extension(\".json\"));\n",
"assert!(Format::Json.has_extension(\"JSON\"));\n",
Expand All @@ -231,7 +231,7 @@ impl Format {
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"use cfgfifo::Format;\n",
"\n",
"assert_eq!(Format::from_extension(\".json\"), Some(Format::Json));\n",
"assert_eq!(Format::from_extension(\"YML\"), Some(Format::Yaml));\n",
Expand All @@ -247,7 +247,7 @@ impl Format {
"# Example\n",
"\n",
"```\n",
"use cfgurate::Format;\n",
"use cfgfifo::Format;\n",
"\n",
"assert_eq!(Format::identify(\"path/to/file.json\").unwrap(), Format::Json);\n",
"assert_eq!(Format::identify(\"path/to/file.RON\").unwrap(), Format::Ron);\n",
Expand Down Expand Up @@ -408,7 +408,7 @@ impl Format {
/// extension, if an I/O error occurs, or if the underlying deserializer
/// returns an error.
pub fn load<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T, LoadError> {
Cfgurate::default().load(path)
Cfgfifo::default().load(path)
}

/// Serialize a value to the given file, with the format automatically
Expand All @@ -420,27 +420,27 @@ pub fn load<T: DeserializeOwned, P: AsRef<Path>>(path: P) -> Result<T, LoadError
/// extension, if an I/O error occurs, or if the underlying serializer returns
/// an error.
pub fn dump<P: AsRef<Path>, T: Serialize>(path: P, value: &T) -> Result<(), DumpError> {
Cfgurate::default().dump(path, value)
Cfgfifo::default().dump(path, value)
}

/// A configurable loader & dumper of serialized data in files.
///
/// By default, a `Cfgurate` instance's [`identify()`][Cfgurate::identify],
/// [`load()`][Cfgurate::load], and [`dump()`][Cfgurate::dump] methods act the
/// By default, a `Cfgfifo` instance's [`identify()`][Cfgfifo::identify],
/// [`load()`][Cfgfifo::load], and [`dump()`][Cfgfifo::dump] methods act the
/// same as [`Format::identify()`], [`load()`], and [`dump()`], but the
/// instance can be customized to only support a subset of enabled [`Format`]s
/// and/or to use a given fallback [`Format`] if identifying a file's format
/// fails.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Cfgurate {
pub struct Cfgfifo {
formats: Vec<Format>,
fallback: Option<Format>,
}

impl Cfgurate {
/// Create a new Cfgurate instance
pub fn new() -> Cfgurate {
Cfgurate {
impl Cfgfifo {
/// Create a new Cfgfifo instance
pub fn new() -> Cfgfifo {
Cfgfifo {
formats: Format::iter().collect(),
fallback: None,
}
Expand Down Expand Up @@ -471,17 +471,17 @@ impl Cfgurate {
"# Example\n",
"\n",
"```\n",
"use cfgurate::{Cfgurate, Format};\n",
"use cfgfifo::{Cfgfifo, Format};\n",
"\n",
"let cfgurate = Cfgurate::new()\n",
"let cfgfifo = Cfgfifo::new()\n",
" .formats([Format::Json, Format::Yaml])\n",
" .fallback(Some(Format::Json));\n",
"\n",
"assert_eq!(cfgurate.identify(\"path/to/file.json\").unwrap(), Format::Json);\n",
"assert_eq!(cfgurate.identify(\"path/to/file.YML\").unwrap(), Format::Yaml);\n",
"assert_eq!(cfgurate.identify(\"path/to/file.ron\").unwrap(), Format::Json);\n",
"assert_eq!(cfgurate.identify(\"path/to/file.cfg\").unwrap(), Format::Json);\n",
"assert_eq!(cfgurate.identify(\"path/to/file\").unwrap(), Format::Json);\n",
"assert_eq!(cfgfifo.identify(\"path/to/file.json\").unwrap(), Format::Json);\n",
"assert_eq!(cfgfifo.identify(\"path/to/file.YML\").unwrap(), Format::Yaml);\n",
"assert_eq!(cfgfifo.identify(\"path/to/file.ron\").unwrap(), Format::Json);\n",
"assert_eq!(cfgfifo.identify(\"path/to/file.cfg\").unwrap(), Format::Json);\n",
"assert_eq!(cfgfifo.identify(\"path/to/file\").unwrap(), Format::Json);\n",
"```\n",
))]
/// # Errors
Expand All @@ -490,7 +490,7 @@ impl Cfgurate {
/// extension is not valid Unicode, or the extension does not belong to a
/// supported [`Format`].
///
/// All error conditions are suppressed if a [fallback][Cfgurate::fallback]
/// All error conditions are suppressed if a [fallback][Cfgfifo::fallback]
/// was set.
pub fn identify<P: AsRef<Path>>(&self, path: P) -> Result<Format, IdentifyError> {
let ext = match (get_ext(path.as_ref()), self.fallback) {
Expand Down Expand Up @@ -535,14 +535,14 @@ impl Cfgurate {
}
}

impl Default for Cfgurate {
/// Same as [`Cfgurate::new()`]
fn default() -> Cfgurate {
Cfgurate::new()
impl Default for Cfgfifo {
/// Same as [`Cfgfifo::new()`]
fn default() -> Cfgfifo {
Cfgfifo::new()
}
}

/// Error type returned by [`Format::identify()`] and [`Cfgurate::identify()`]
/// Error type returned by [`Format::identify()`] and [`Cfgfifo::identify()`]
#[derive(Clone, Debug, Eq, Error, PartialEq)]
pub enum IdentifyError {
/// Returned if the file path's extension did not correspond to a known &
Expand Down Expand Up @@ -644,7 +644,7 @@ pub enum DeserializeError {
Yaml(#[from] serde_yaml::Error),
}

/// Error type returned by [`load()`] and [`Cfgurate::load()`]
/// Error type returned by [`load()`] and [`Cfgfifo::load()`]
#[derive(Debug, Error)]
pub enum LoadError {
/// Returned if the file format could not be identified from the file
Expand All @@ -661,7 +661,7 @@ pub enum LoadError {
Deserialize(#[from] DeserializeError),
}

/// Error type returned by [`dump()`] and [`Cfgurate::dump()`]
/// Error type returned by [`dump()`] and [`Cfgfifo::dump()`]
#[derive(Debug, Error)]
pub enum DumpError {
/// Returned if the file format could not be identified from the file
Expand Down Expand Up @@ -709,7 +709,7 @@ mod tests {
Err(IdentifyError::Unknown(ext.clone()))
);
assert_eq!(
Cfgurate::default().identify(path),
Cfgfifo::default().identify(path),
Err(IdentifyError::Unknown(ext))
);
}
Expand All @@ -721,7 +721,7 @@ mod tests {
let path = std::ffi::OsStr::from_bytes(b"file.js\xF6n");
assert_eq!(Format::identify(path), Err(IdentifyError::NotUnicode));
assert_eq!(
Cfgurate::default().identify(path),
Cfgfifo::default().identify(path),
Err(IdentifyError::NotUnicode)
);
}
Expand All @@ -735,7 +735,7 @@ mod tests {
]);
assert_eq!(Format::identify(&path), Err(IdentifyError::NotUnicode));
assert_eq!(
Cfgurate::default().identify(path),
Cfgfifo::default().identify(path),
Err(IdentifyError::NotUnicode)
);
}
Expand All @@ -744,7 +744,7 @@ mod tests {
fn identify_no_ext() {
assert_eq!(Format::identify("file"), Err(IdentifyError::NoExtension));
assert_eq!(
Cfgurate::default().identify("file"),
Cfgfifo::default().identify("file"),
Err(IdentifyError::NoExtension)
);
}
Expand Down Expand Up @@ -1016,7 +1016,7 @@ mod tests {
}
}

mod cfgurate {
mod cfgfifo {
#[allow(unused_imports)]
use super::*;

Expand All @@ -1029,7 +1029,7 @@ mod tests {
))]
#[test]
fn default() {
let cfg = Cfgurate::default();
let cfg = Cfgfifo::default();
assert_eq!(cfg.identify("file.json").unwrap(), Format::Json);
assert_eq!(cfg.identify("file.json5").unwrap(), Format::Json5);
assert_eq!(cfg.identify("file.Ron").unwrap(), Format::Ron);
Expand All @@ -1048,7 +1048,7 @@ mod tests {
))]
#[test]
fn fallback() {
let cfg = Cfgurate::new().fallback(Some(Format::Json));
let cfg = Cfgfifo::new().fallback(Some(Format::Json));
assert_eq!(cfg.identify("file.json").unwrap(), Format::Json);
assert_eq!(cfg.identify("file.json5").unwrap(), Format::Json5);
assert_eq!(cfg.identify("file.Ron").unwrap(), Format::Ron);
Expand All @@ -1061,7 +1061,7 @@ mod tests {
#[cfg(all(feature = "json", feature = "toml"))]
#[test]
fn formats() {
let cfg = Cfgurate::new().formats([Format::Json, Format::Toml]);
let cfg = Cfgfifo::new().formats([Format::Json, Format::Toml]);
assert_eq!(cfg.identify("file.json").unwrap(), Format::Json);
assert!(cfg.identify("file.json5").is_err());
assert!(cfg.identify("file.Ron").is_err());
Expand All @@ -1074,7 +1074,7 @@ mod tests {
#[cfg(all(feature = "json", feature = "toml", feature = "yaml"))]
#[test]
fn formats_fallback() {
let cfg = Cfgurate::new()
let cfg = Cfgfifo::new()
.formats([Format::Json, Format::Toml])
.fallback(Some(Format::Yaml));
assert_eq!(cfg.identify("file.json").unwrap(), Format::Json);
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "json")]
use crate::Config;
use cfgurate::*;
use cfgfifo::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::{read_to_string, Seek, Write};
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/json5.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "json5")]
use crate::Config;
use cfgurate::*;
use cfgfifo::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::{read_to_string, Seek, Write};
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/ron.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "ron")]
use crate::RonConfig;
use cfgurate::*;
use cfgfifo::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::{read_to_string, Seek, Write};
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/toml.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "toml")]
use crate::Config;
use cfgurate::*;
use cfgfifo::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::{read_to_string, Seek, Write};
Expand Down
2 changes: 1 addition & 1 deletion tests/formats/yaml.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(feature = "yaml")]
use crate::Config;
use cfgurate::*;
use cfgfifo::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
use std::io::{read_to_string, Seek, Write};
Expand Down

0 comments on commit dbaf882

Please sign in to comment.