-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial changes to drop default serde dependency #255
Initial changes to drop default serde dependency #255
Conversation
I like this a lot. There are even quite quite significant benefits for people who are using the serde formats with this. However what I'm not a fan of is that the snapshot format no longer carries info directly and expression is missing entirely: Before: ---
source: tests/test_settings.rs
description: The snapshot are four integers
expression: "vec![1, 2, 3, 4]"
info:
env:
ENVIRONMENT: production
cmdline:
- my-tool
- run
--- After: ---
source: tests/test_settings.rs
description: The snapshot is four integers
info: "env: [\"ENVIRONMENT\", \"production\"], cmdline: [\"my-tool\", \"run\"]"
--- I generally think that the info change to a string would be something I would not be okay with. Since apparently More importantly in general I also generally believe that In the interest of cutting out more dependencies the Good work overall. I think this can turn into something quite valuable! Oh in terms of if this could be merged: absolutely. Mostly because I believe this could even be smooth by going in two version steps:
About |
I pushed a small fix for |
I totally agree with all the feedback. A brief summary:
The one thing I still have questions on is
I'm assuming that you're mixing up YAML and TOML when it comes to parsing the manifests unless there's something else I'm missing Also worth noting that
Awesome! That's great to hear I'll work towards addressing all the feedback above, and thanks for fixing |
YAML is a superset of JSON so for the purpose of reading cargo manifest files you can use the yaml-rust crate: use std::process::Command;
fn main() {
let out = Command::new("cargo")
.arg("read-manifest")
.output()
.unwrap();
let manifest = yaml_rust::YamlLoader::load_from_str(
std::str::from_utf8(&out.stdout).unwrap()).unwrap();
dbg!(manifest);
} About this in particular:
For now I would probably keep the logic here but since insta (not cargo insta) only needs to emit these files I wouldn't be entirely opposed to a minimal JSON emitter which can be used for snapshots and this. #256 already showed that relying on generic serialization libraries is not great for insta as formats change all the time with updates, so actually having an embedded JSON emitter in insta is something I would probably prefer having anyways. But in the interest of keeping the PR mergeable I think that should be a followup task. So I would keep the json dependency exclusively for the inline snapshots pending file for now, and I will then follow up with something that kills that too. |
…anHorror/insta into experiment-with-serde-removal
Pushed changes that:
use insta::internals::Content;
let raw_info = Content::Map(vec![
(
Content::from("env"),
Content::Seq(vec![
Content::from("ENVIRONMENT"),
Content::from("production"),
]),
),
(
Content::from("cmdline"),
Content::Seq(vec![Content::from("my-tool"), Content::from("run")]),
),
]);
with_settings!({description => "The snapshot is four integers", raw_info => &raw_info}, {
assert_debug_snapshot!(vec![1, 2, 3, 4])
});
I think this is a good stopping point for this PR to avoid scope creep and trying out a bunch of changes that may need hashing out. With that said the pending work left is (which I'm certainly happy to work on, but feel free to pick some if you want)
|
This looks very good. I think I will be merging this to master and then look from there how to close on the remaining items. |
serde
dep
Related #214
Motivation
This was an experiment to see how difficult it would be to drop
serde
usage by default (includingserde_json
andserde_yaml
). The idea was to see how lightweightinsta
could be in both clean compile times and the number of dependencies if someone was just using the debug, display, and string snapshot formats(Spoilers) 💥 Breaking Changes 💥
Deserialie
andSerialize
trait from several publicly exposed typesinfo
got changed to aString
although I think it could just be moved behind theserialization
feature flagassert_yaml_snapshot!()
andassert_json_snapshot!()
formats got moved behind theyaml
andjson
feature flags respectivelyImplementation
The
serde
implementation was replaced by a handwritten baby version that somewhat follows the same principle. The idea is still to translate the underlying data format to a common structure (in this casecrate::parse::Value
) and to have logic to serialize and deserialize data forstruct
s with that common formatTo make the implementation simple the common format is kept very basic to make it easy to map to the data returned by the parsers (This can be seen in
src/parse/mod.rs
). Also the mapping of the common data format to different structs had to be handwritten instead of just being able to use#[derive(Deserialize, Serialize)]
(This can be seen insrc/snapshot.rs
)Results
Big dislaimer: The main benefit is to people who can get by with just the debug, display, and string snapshot formats
This drastically drops the number of default dependencies
Along with having a large impact on clean build times (Note before filters out crates that built in less than 0.3 seconds while after filters out less than 0.2s)
Before
After
I also took a brief survey over 20 highly downloaded crates that use
insta
to see how many use formats outside of debug, default, and string. Fromonly
cynic
,full_moon
, andhtml_parser
used a format outside of debug, default, and string.yaml
forcynic
andfull_moon
andjson
forhtml_parser
Pending Work
I didn't want to take the time to polish everything since I'm not sure this will even be merged considering it involves breaking changes
info
back toSerialize
probably