serializer features (toml doesn't work)
This commit is contained in:
parent
1c3b8069aa
commit
4d8083fb11
4 changed files with 299 additions and 12 deletions
223
Cargo.lock
generated
223
Cargo.lock
generated
|
@ -35,16 +35,31 @@ version = "0.22.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bliplab"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bliplib",
|
||||
"cfg-exclusive",
|
||||
"cfg-if",
|
||||
"derive-new",
|
||||
"json5",
|
||||
"ron",
|
||||
"serde",
|
||||
"serde-lexpr",
|
||||
"serde_json",
|
||||
"serde_with",
|
||||
"serde_yaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -69,6 +84,15 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.18.1"
|
||||
|
@ -90,6 +114,17 @@ dependencies = [
|
|||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-exclusive"
|
||||
version = "0.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e42d03de728dc16ee8777daec6aab51e86f52de07b051214d55388d61571fadc"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.95",
|
||||
"quote 1.0.40",
|
||||
"syn 2.0.103",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.1"
|
||||
|
@ -115,6 +150,25 @@ version = "0.8.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
|
@ -212,6 +266,16 @@ dependencies = [
|
|||
"syn 0.15.44",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dyn-clone"
|
||||
version = "1.0.19"
|
||||
|
@ -242,6 +306,16 @@ version = "0.5.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9716a0a1c5bba06eeccce22ff33a89dc961d88f02f0d450a55c1bade6cbcdd5"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getset"
|
||||
version = "0.1.6"
|
||||
|
@ -346,12 +420,44 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "json5"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lexpr"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a84de6a9df442363b08f5dbf0cd5b92edc70097b89c4ce4bfea4679fe48bc67"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"lexpr-macros",
|
||||
"ryu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lexpr-macros"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36b5cb8bb985c81a8ac1a0f8b5c4865214f574ddd64397ef7a99c236e21f35bb"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.95",
|
||||
"quote 1.0.40",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.174"
|
||||
|
@ -411,6 +517,50 @@ version = "1.21.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "pest"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"thiserror",
|
||||
"ucd-trie",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_derive"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb056d9e8ea77922845ec74a1c4e8fb17e7c218cc4fc11a15c5d25e189aa40bc"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_generator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_generator"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e404e638f781eb3202dc82db6760c8ae8a1eeef7fb3fa8264b2ef280504966"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_meta",
|
||||
"proc-macro2 1.0.95",
|
||||
"quote 1.0.40",
|
||||
"syn 2.0.103",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_meta"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd1101f170f5903fde0914f899bb503d9ff5271d7ba76bbb70bea63690cc0d5"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
|
@ -495,6 +645,19 @@ dependencies = [
|
|||
"syn 2.0.103",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "beceb6f7bf81c73e73aeef6dd1356d9a1b2b4909e1f0fc3e59b034f9572d7b7f"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bitflags",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.21"
|
||||
|
@ -528,6 +691,16 @@ dependencies = [
|
|||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde-lexpr"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb4cda13396159f59e7946118cdac0beadeecfb7cf76b197f4147e546f4ead6f"
|
||||
dependencies = [
|
||||
"lexpr",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
|
@ -582,6 +755,30 @@ dependencies = [
|
|||
"syn 2.0.103",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.9.34+deprecated"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
|
||||
dependencies = [
|
||||
"indexmap 2.9.0",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
"unsafe-libyaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
|
@ -689,6 +886,18 @@ dependencies = [
|
|||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-trie"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
|
@ -701,6 +910,18 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
|
||||
[[package]]
|
||||
name = "unsafe-libyaml"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.100"
|
||||
|
|
18
Cargo.toml
18
Cargo.toml
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "bliplab"
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
edition = "2024"
|
||||
authors = ["Breval Ferrari <breval.ferrari@fish.golf>"]
|
||||
description = "Tool to combine several BLIP channels in a song"
|
||||
|
@ -15,13 +15,25 @@ anyhow = { version = "1", optional = true }
|
|||
bliplib = { version = "0.2.5", default-features = false }
|
||||
derive-new = "0.7.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
serde_with = "3.13"
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
serde_yaml = { version = "0.9.33", optional = true }
|
||||
ron = { version = "0.10", optional = true }
|
||||
json5 = { version = "0.4", optional = true }
|
||||
serde-lexpr = { version = "0.1", optional = true }
|
||||
cfg-exclusive = { version = "0.0.1", optional = true }
|
||||
cfg-if = { version = "1.0", optional = true }
|
||||
|
||||
[features]
|
||||
bin = ["serde_json", "anyhow"]
|
||||
bin = ["anyhow", "cfg-exclusive", "cfg-if"]
|
||||
example-skip-defaults = []
|
||||
|
||||
json = ["serde_json"]
|
||||
json5 = ["dep:json5"]
|
||||
yaml = ["serde_yaml"]
|
||||
ron = ["dep:ron"]
|
||||
lexpr = ["serde-lexpr"]
|
||||
|
||||
[[bin]]
|
||||
name = "bliplab"
|
||||
path = "src/cli/main.rs"
|
||||
|
|
|
@ -1,9 +1,28 @@
|
|||
//! See [BLIPlab](https://docs.rs/bliplab)
|
||||
|
||||
use std::{env::args, fs::File};
|
||||
#[cfg(not(any(
|
||||
feature = "json",
|
||||
feature = "json5",
|
||||
feature = "yaml",
|
||||
feature = "ron",
|
||||
feature = "lexpr"
|
||||
)))]
|
||||
compile_error!("You must select one serializer / deserializer feature");
|
||||
|
||||
cfg_exclusive::cfg_exclusive! {
|
||||
serializer_deserializer,
|
||||
["json", "json5", "yaml", "ron", "lexpr"],
|
||||
"You can select only one serializer / deserializer feature (json, json5, yaml, toml, ron or lexpr)"
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "json5", feature = "ron"))]
|
||||
use std::io::read_to_string;
|
||||
use std::{env::args, fs::File, io::Read};
|
||||
|
||||
use anyhow::Context;
|
||||
use bliplab::{Channel, PathOrString, Song, VariableChange};
|
||||
use cfg_if::cfg_if;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
|
||||
const TARGET: &str = "BLIP lab file";
|
||||
|
||||
|
@ -33,13 +52,49 @@ fn example_song() -> Song<'static> {
|
|||
)
|
||||
}
|
||||
|
||||
fn prettify<V: Serialize>(value: &V) -> anyhow::Result<String> {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "json")] {
|
||||
serde_json::to_string_pretty(value).map_err(Into::into)
|
||||
} else if #[cfg(feature = "json5")] {
|
||||
json5::to_string(value).map_err(Into::into)
|
||||
} else if #[cfg(feature = "yaml")] {
|
||||
serde_yaml::to_string(value).map_err(Into::into)
|
||||
} else if #[cfg(feature = "ron")] {
|
||||
ron::to_string(value).map_err(Into::into)
|
||||
} else if #[cfg(feature = "lexpr")] {
|
||||
serde_lexpr::to_string(value).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_reader<R: Read, T: DeserializeOwned>(reader: R) -> anyhow::Result<T> {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "json")] {
|
||||
serde_json::from_reader(reader).map_err(Into::into)
|
||||
} else if #[cfg(feature = "json5")] {
|
||||
json5::from_str(&read_to_string(reader)?).map_err(Into::into)
|
||||
} else if #[cfg(feature = "yaml")] {
|
||||
serde_yaml::from_reader(reader).map_err(Into::into)
|
||||
} else if #[cfg(feature = "ron")] {
|
||||
ron::from_str(&read_to_string(reader)?).map_err(Into::into)
|
||||
} else if #[cfg(feature = "lexpr")] {
|
||||
serde_lexpr::from_reader(reader).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let string = args().skip(1).next().context(format!(
|
||||
"You need to give a single argument with the filename of your {TARGET}."
|
||||
))?;
|
||||
if let Some(argument) = string.strip_prefix("--") {
|
||||
if argument == "example" {
|
||||
println!("{}", serde_json::to_string_pretty(&example_song()).unwrap());
|
||||
println!(
|
||||
"{}",
|
||||
prettify(&example_song())
|
||||
.context("Can't serialize the example song, this is a bug.")?
|
||||
);
|
||||
} else if argument == "help" {
|
||||
println!(
|
||||
"BLIP lab file player. Pass it a path to a {TARGET} or use with \"--example\" for an example {TARGET}."
|
||||
|
@ -48,15 +103,13 @@ fn main() -> anyhow::Result<()> {
|
|||
eprintln!("Unknown argument: \"{argument}\"");
|
||||
}
|
||||
} else {
|
||||
let song: Song = serde_json::from_reader(
|
||||
File::open(string).context(format!("Failed to open the {TARGET}."))?,
|
||||
)
|
||||
let song: Song =
|
||||
from_reader(File::open(string).context(format!("Failed to open the {TARGET}."))?)
|
||||
.context(format!("Failed to read the {TARGET}."))?;
|
||||
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&song)
|
||||
.context("Failed to pretty print the song! What?!")?
|
||||
prettify(&song).context("Failed to pretty print the song! What?!")?
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use derive_new::new;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{DisplayFromStr, serde_as};
|
||||
|
||||
#[cfg(feature = "example-skip-defaults")]
|
||||
fn is_default<T: Default + PartialEq>(t: &T) -> bool {
|
||||
t == &T::default()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue