Skip to content

Commit 797ad69

Browse files
committed
shared: Make option parsing and optional feature
This is a breaking change for anyone using default-features = false and option parsing.
1 parent ebc6dfd commit 797ad69

File tree

8 files changed

+37
-5
lines changed

8 files changed

+37
-5
lines changed

ci/script.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DIR="$(cd "$(dirname $0)/.." && pwd)"
77
cd "$DIR/json_typegen_shared"
88
cargo build --target "$TARGET" --verbose
99
cargo test --target "$TARGET" --verbose
10+
cargo build --target "$TARGET" --no-default-features --verbose
1011

1112
cd "$DIR/json_typegen_cli"
1213
cargo build --target "$TARGET" --verbose

json_typegen_shared/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ edition = "2018"
1212

1313
[features]
1414
unstable = []
15-
default = ["remote-samples", "local-samples"]
15+
default = ["remote-samples", "local-samples", "option-parsing"]
1616
remote-samples = ["reqwest"]
1717
local-samples = []
18+
option-parsing = ["syn", "synom"]
1819

1920
[dependencies]
2021
serde = "1.0"
@@ -26,8 +27,8 @@ lazy_static = "1.2"
2627
linked-hash-map = "0.5.3"
2728
Inflector = "0.11"
2829
regex = "1.1"
29-
syn = { version = "0.11", features = ["full", "parsing"] }
30-
synom = "0.11.3"
30+
syn = { version = "0.11", features = ["full", "parsing"], optional = true }
31+
synom = { version = "0.11.3", optional = true }
3132
unindent = "0.1.2"
3233

3334
[dev-dependencies]

json_typegen_shared/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,27 @@ If you want to use this crate directly, be prepared for breaking changes to happ
1111
to let me know what you are using. (Breaking changes may still happen,
1212
but then I'll at least try to keep your use-case in mind if possible.
1313
This has happened enough by now that there are parts I already consider public API.)
14+
15+
## Crate feature flags
16+
17+
All of these flags are on by default,
18+
but you can avoid dependencies you don't care about disabling some or all of them,
19+
with e.g. something like this to only enable option parsing:
20+
21+
```
22+
json_typegen_shared = { version = "*", default-features = false, features = ["option-parsing"] }
23+
```
24+
25+
### `remote-samples`
26+
27+
Required to load samples from URLs.
28+
29+
### `local-samples`
30+
31+
Required to load samples from local paths.
32+
33+
### `option-parsing`
34+
35+
Required to parse an options object from a string.
36+
Since this is required for code generation from macro-like strings,
37+
this is also required for the functions `codegen_from_macro` and `codegen_from_macro_input`.

json_typegen_shared/src/generation/serde_case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! case of the source (e.g. `my-field`, `MY_FIELD`).
33
//!
44
//! Manually vendored from serde_derive/internals
5-
//! https://github.com/serde-rs/serde/blob/4eb580790dd6c96089b92942a5f481b21df4feaf/serde_derive/src/internals/case.rs
5+
//! <https://github.com/serde-rs/serde/blob/4eb580790dd6c96089b92942a5f481b21df4feaf/serde_derive/src/internals/case.rs>
66
#![allow(dead_code)]
77

88
// See https://users.rust-lang.org/t/psa-dealing-with-warning-unused-import-std-ascii-asciiext-in-today-s-nightly/13726

json_typegen_shared/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod generation;
2424
mod hints;
2525
mod inference;
2626
mod options;
27+
#[cfg(feature = "option-parsing")]
2728
pub mod parse;
2829
mod shape;
2930
mod unwrap;
@@ -68,6 +69,7 @@ enum SampleSource<'a> {
6869
Text(&'a str),
6970
}
7071

72+
#[cfg(feature = "option-parsing")]
7173
/// Generate code from a `json_typegen` macro invocation
7274
pub fn codegen_from_macro(input: &str) -> Result<String, JTError> {
7375
let macro_input = parse::full_macro(input)?;
@@ -79,6 +81,7 @@ pub fn codegen_from_macro(input: &str) -> Result<String, JTError> {
7981
)
8082
}
8183

84+
#[cfg(feature = "option-parsing")]
8285
/// Generate code from the arguments to a `json_typegen` macro invocation
8386
pub fn codegen_from_macro_input(input: &str) -> Result<String, JTError> {
8487
let macro_input = parse::macro_input(input)?;

json_typegen_shared/src/options.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl Default for Options {
4141
}
4242
}
4343

44+
#[cfg(feature = "option-parsing")]
4445
impl Options {
4546
pub(crate) fn macro_default() -> Options {
4647
let mut options = Options::default();

json_typegen_shared/src/parse.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//! Functions for parsing `json_typegen` macro invocations and their arguments
2+
//!
3+
//! Requires the "option-parsing" feature
24
35
use syn;
46
use syn::parse::{boolean, ident, string};

json_typegen_wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ crate-type = ["cdylib"]
1414
[dependencies]
1515
cfg-if = "0.1.5"
1616
wasm-bindgen = "0.2.71"
17-
json_typegen_shared = { path = "../json_typegen_shared", default-features = false, features = [] }
17+
json_typegen_shared = { path = "../json_typegen_shared", default-features = false, features = ["option-parsing"] }
1818

1919
# The `console_error_panic_hook` crate provides better debugging of panics by
2020
# logging them with `console.error`. This is great for development, but requires

0 commit comments

Comments
 (0)