Skip to content

Commit

Permalink
Initial changes to drop default serde dependency (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Aug 5, 2022
1 parent 0f775e9 commit b9d58c2
Show file tree
Hide file tree
Showing 29 changed files with 1,157 additions and 525 deletions.
29 changes: 21 additions & 8 deletions Cargo.toml
Expand Up @@ -22,7 +22,7 @@ default = ["colors"]

# when the redactions feature is enabled values can be redacted in serialized
# snapshots.
redactions = ["pest", "pest_derive"]
redactions = ["pest", "pest_derive", "serialization"]

# Enables support for running filters on snapshot
filters = ["regex"]
Expand All @@ -34,26 +34,39 @@ glob = ["walkdir", "globset"]
colors = ["console"]

# This feature is now just always enabled because we use yaml internally now.
serialization = []
serialization = ["serde"]

# This feature is no longer used as snapshot name detection was changed.
backtrace = []

# Serialization formats
# TODO: This could be cleaner by using "dep:csv" without renaming the dep, but
# this technique allows for a lower MSRV
csv = ["dep_csv", "serialization"]
json = ["serde_json", "serialization"]
ron = ["dep_ron", "serialization"]
toml = ["dep_toml", "serialization"]
yaml = ["serde_yaml", "serialization"]

[dependencies]
csv = { version = "1.1.4", optional = true }
serde = { version = "1.0.117", features = ["derive"] }
serde_yaml = "0.8.26"
dep_csv = { package = "csv", version = "1.1.4", optional = true }
console = { version = "0.15.1", optional = true, default-features = false }
serde_json = "1.0.59"
pest = { version = "2.1.3", optional = true }
pest_derive = { version = "2.1.0", optional = true }
ron = { version = "0.7.1", optional = true }
toml = { version = "0.5.7", optional = true }
dep_ron = { package = "ron", version = "0.7.1", optional = true }
dep_toml = { package = "toml", version = "0.5.7", optional = true }
globset = { version = "0.4.6", optional = true }
walkdir = { version = "2.3.1", optional = true }
similar = { version = "2.1.0", features = ["inline"] }
once_cell = "1.9.0"
regex = { version = "1.6.0", default-features = false, optional = true, features = ["std", "unicode"] }
yaml-rust = "0.4.5"
dep_json = { package = "json", version = "0.12.4" }
serde = { version = "1.0.117", optional = true }
serde_json = { version = "1.0.59", optional = true }
serde_yaml = { version = "0.8.26", optional = true }
linked-hash-map = "0.5.6"

[dev-dependencies]
serde = { version = "1.0.117", features = ["derive"] }
similar-asserts = "1.4.2"
13 changes: 11 additions & 2 deletions cargo-insta/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo-insta/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ edition = "2018"
readme = "README.md"

[dependencies]
insta = { version = "=1.17.1", path = "..", features = ["redactions"] }
insta = { version = "=1.17.1", path = "..", features = ["json", "yaml", "redactions"] }
console = "0.15.1"
structopt = "0.3.20"
serde = { version = "1.0.117", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion cargo-insta/integration-tests/Cargo.toml
Expand Up @@ -8,6 +8,6 @@ edition = "2018"

[dependencies]
dircpy = "0.3.4"
insta = { version = "1.1.0", path = "../..", features = ["redactions", "glob"] }
insta = { version = "1.1.0", path = "../..", features = ["json", "yaml", "redactions", "glob"] }
walkdir = "2.3.1"
serde = { version = "1.0.117", features = ["derive"] }
30 changes: 30 additions & 0 deletions src/content/error.rs
@@ -0,0 +1,30 @@
use std::{error, fmt, result};

use super::Content;

pub type Result<T> = result::Result<T, Error>;

#[derive(Debug)]
pub enum Error {
InvalidStructField(Content),
FailedParsingYaml,
UnexpectedDataType,
MissingField,
UnsupportedDataType,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidStructField(content) => write!(f, "Invalid struct field: {:?}", content),
Self::FailedParsingYaml => f.write_str("Failed parsing the provided YAML text"),
Self::UnexpectedDataType => {
f.write_str("The present data type wasn't what was expected")
}
Self::MissingField => f.write_str("A required field was missing"),
Self::UnsupportedDataType => f.write_str("Failed converting an unsupported data type"),
}
}
}

impl error::Error for Error {}

0 comments on commit b9d58c2

Please sign in to comment.