Skip to content

Commit addcab4

Browse files
authored
Merge pull request #11 from simd-lite/rust-1.64-updates
Updates for Rust 1.64.0
2 parents eaed179 + 278fe4a commit addcab4

21 files changed

Lines changed: 411 additions & 243 deletions

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: cargo
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10

.github/workflows/nightly.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Tests - Nightly
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
10+
jobs:
11+
build-nightly:
12+
strategy:
13+
matrix:
14+
rustflags:
15+
- '-C target-cpu=native'
16+
features:
17+
- ''
18+
- '--features 128bit'
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v1
22+
- uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: nightly
25+
override: true
26+
- name: Build
27+
env:
28+
RUSTFLAGS: ${{ matrix.rustflags }}
29+
run: cargo build ${{ matrix.features }}
30+
- name: Run tests
31+
env:
32+
RUSTFLAGS: ${{ matrix.rustflags }}
33+
run: cargo test ${{ matrix.features }}

.github/workflows/quality.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Quality
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
10+
jobs:
11+
clippy_check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- uses: actions-rs/toolchain@v1
16+
with:
17+
toolchain: stable
18+
profiles: minimal
19+
override: true
20+
components: rustfmt,clippy
21+
- name: Validate cargo format
22+
run: cargo fmt -- --check
23+
- name: Check workflow permissions
24+
id: check_permissions
25+
uses: scherermichael-oss/action-has-permission@1.0.6
26+
with:
27+
required-permission: write
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30+
- name: Run clippy action to produce annotations
31+
uses: actions-rs/clippy-check@v1
32+
if: steps.check_permissions.outputs.has-permission
33+
env:
34+
RUSTFLAGS: "-C target-cpu=native"
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
args: --all
38+
- name: Run clippy manually without annotations
39+
if: ${{ !steps.check_permissions.outputs.has-permission }}
40+
env:
41+
RUSTFLAGS: "-C target-cpu=native"
42+
run: cargo clippy --all
43+
coverage:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v1
47+
- uses: actions-rs/toolchain@v1
48+
with:
49+
toolchain: stable
50+
profile: minimal
51+
components: llvm-tools-preview
52+
- name: Install cargo-llvm-cov
53+
uses: taiki-e/install-action@cargo-llvm-cov
54+
- name: Run codecov
55+
env:
56+
RUSTFLAGS: "-C target-cpu=native"
57+
run: cargo llvm-cov --lcov --output-path lcov.txt
58+
- uses: codecov/codecov-action@v3
59+
with:
60+
files: ./lcov.txt # optional
61+
flags: ${{ env.flags }} # optional
62+
fail_ci_if_error: true # optional (default = false)
63+
verbose: true # optional (default = false)

.github/workflows/tests.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
rustflags:
14+
- '-C target-cpu=native'
15+
features:
16+
- ''
17+
- '--features 128bit'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v1
21+
- uses: actions-rs/toolchain@v1
22+
with:
23+
toolchain: stable
24+
override: true
25+
- name: Build
26+
env:
27+
RUSTFLAGS: ${{ matrix.rustflags }}
28+
run: cargo build ${{ matrix.features }}
29+
- name: Run tests
30+
env:
31+
RUSTFLAGS: ${{ matrix.rustflags }}
32+
run: cargo test ${{ matrix.features }}

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ documentation = "https://docs.rs/simd-json-derive"
99
readme = "README.md"
1010
homepage = "https://docs.rs/simd-json-derive"
1111
repository = "https://github.com/simd-lite/simd-json-derive/"
12+
rust-version = "1.59"
1213

1314
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1415

@@ -28,3 +29,13 @@ serde = "1"
2829
default = ["impl-chrono"]
2930
impl-chrono = ["chrono"]
3031
128bit = ["simd-json-derive-int/128bit", "simd-json/128bit"]
32+
allow-non-simd = [
33+
"simd-json-derive-int/allow-non-simd",
34+
"simd-json/allow-non-simd",
35+
]
36+
37+
[package.metadata.docs.rs]
38+
features = ["allow-non-simd"]
39+
40+
[[example]]
41+
name = "enum1"

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
1-
Derives for high performance JSON serialisation (and eventually deserialisation).
1+
# simd-json-derive
22

3-
Attributres are supported for both `#[simd_json(...)]` and for compatibilty also for `#[serde(...)]` and follow the same nameing conventions as serde.
3+
[![Latest version](https://img.shields.io/crates/v/simd-json-derive.svg)](https://crates.io/crates/simd-json-derive)
4+
[![documentation](https://img.shields.io/docsrs/simd-json-derive)](https://docs.rs/simd-json-derive)
5+
![License](https://img.shields.io/crates/l/simd-json-derive.svg)
6+
7+
8+
Derives for high performance JSON serialisation and deserialisation.
9+
10+
## Usage
11+
12+
```rust
13+
14+
#[derive(Serialize, Deserialize, Debug)]
15+
#[simd_json(deny_unknown_fields, rename_all = "camelCase")]
16+
struct MyStruct {
17+
first_field: String,
18+
#[simd_json(rename = "foo")]
19+
second_field: Option<usize>
20+
}
21+
22+
fn main -> Result<(), simd_json::Error> {
23+
let my_struct = MyStruct {
24+
first_field: "i am first".to_string(),
25+
second_field: None
26+
}
27+
println!("Before: {my_struct:?}");
28+
let mut json_string = my_struct.json_string()?;
29+
let deserialized = MyStruct::from_str(json_string.as_mut_str())?;
30+
println!("After: {deserialized:?}");
31+
}
32+
```
33+
34+
## Supported Attributes
35+
36+
Attributres are supported for both `#[simd_json(...)]` and for compatibilty also for `#[serde(...)]` and follow the same naming conventions as serde.
437

538
For fields:
639

740
* `rename = "new_name"` - renames a field
841

942
For structs:
1043

11-
* `rename_all = "camelCase"` - renames all (not otherwise renamed) based on the rule, `camelCase` is currently supportd
44+
* `rename_all = "camelCase"` - renames all (not otherwise renamed) based on the rule, `camelCase` is currently supported
45+
* `deny_unknown_fields` - Errors if unknown fields are encountered

examples/enum1.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
#[derive(simd_json_derive::Deserialize)]
1+
use simd_json_derive::{Deserialize, Serialize};
2+
3+
#[derive(Deserialize, Serialize, Debug)]
24
pub enum StoredVariants {
35
YesNo(bool),
46
Small(u8, i8),
57
Signy(i64),
68
Stringy(String),
79
}
810

9-
fn main() {}
11+
fn main() {
12+
let x = StoredVariants::Signy(-1);
13+
let mut serialized = x.json_string().expect("serialization shouldnt fail :(");
14+
let deserialized = StoredVariants::from_str(serialized.as_mut_str())
15+
.expect("serialized stuff should be deserializable");
16+
println!("Serialized: {x:?}");
17+
println!("Deserialized: {deserialized:?}");
18+
}

simd-json-derive-int/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ proc-macro = true
1515
proc-macro2 = "1.0"
1616
quote = "1.0"
1717
syn = { version = "1.0", features = ["visit", "extra-traits"] }
18-
simd-json = { version = "0.6", features = ["allow-non-simd"] }
18+
simd-json = "0.6"
1919

2020
[features]
21+
default = ["allow-non-simd"]
2122
128bit = ["simd-json/128bit"]
23+
allow-non-simd = ["simd-json/allow-non-simd"]

simd-json-derive-int/src/args.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,22 @@ impl RenameAll {
6969
#[derive(Debug)]
7070
pub(crate) struct StructAttrs {
7171
rename_all: RenameAll,
72-
// deny_unknown_fields: bool,
72+
deny_unknown_fields: bool,
7373
}
7474

7575
impl Default for StructAttrs {
7676
fn default() -> Self {
7777
StructAttrs {
7878
rename_all: RenameAll::None,
79-
// deny_unknown_fields: false,
79+
deny_unknown_fields: false,
8080
}
8181
}
8282
}
8383

8484
impl Parse for StructAttrs {
8585
fn parse(input: ParseStream) -> syn::Result<Self> {
8686
let mut rename_all = RenameAll::None;
87-
let mut _deny_unknown_fields = false;
87+
let mut deny_unknown_fields = false;
8888
while !input.is_empty() {
8989
let attr: Ident = input.parse()?;
9090
match attr.to_string().as_str() {
@@ -103,7 +103,7 @@ impl Parse for StructAttrs {
103103
}
104104
}
105105
"deny_unknown_fields" => {
106-
_deny_unknown_fields = true;
106+
deny_unknown_fields = true;
107107
}
108108
other => {
109109
return Err(syn::Error::new(
@@ -118,7 +118,7 @@ impl Parse for StructAttrs {
118118
}
119119
Ok(StructAttrs {
120120
rename_all,
121-
// deny_unknown_fields,
121+
deny_unknown_fields,
122122
})
123123
}
124124
}
@@ -143,24 +143,29 @@ pub(crate) fn get_attr<'field>(
143143
.next()
144144
}
145145

146-
pub(crate) fn name(struct_attr: &StructAttrs, field: &Field) -> Option<String> {
147-
if let Some(attr) = get_attr(&field.attrs, "simd_json")
148-
.map(field_attrs)
149-
.and_then(|a| a.rename)
150-
{
151-
Some(format!("{}:", simd_json::OwnedValue::from(attr).encode()))
152-
} else if let Some(attr) = get_attr(&field.attrs, "serde")
153-
.map(field_attrs)
154-
.and_then(|a| a.rename)
155-
{
156-
Some(format!("{}:", simd_json::OwnedValue::from(attr).encode()))
157-
} else {
158-
field.ident.as_ref().map(|ident| {
159-
format!(
160-
"{}:",
161-
simd_json::OwnedValue::from(struct_attr.rename_all.apply(&ident.to_string()))
162-
.encode()
163-
)
164-
})
146+
impl StructAttrs {
147+
pub(crate) fn deny_unknown_fields(&self) -> bool {
148+
self.deny_unknown_fields
149+
}
150+
151+
pub(crate) fn name(&self, field: &Field) -> Option<String> {
152+
if let Some(attr) = get_attr(&field.attrs, "simd_json")
153+
.map(field_attrs)
154+
.and_then(|a| a.rename)
155+
{
156+
Some(format!("{}:", simd_json::OwnedValue::from(attr).encode()))
157+
} else if let Some(attr) = get_attr(&field.attrs, "serde")
158+
.map(field_attrs)
159+
.and_then(|a| a.rename)
160+
{
161+
Some(format!("{}:", simd_json::OwnedValue::from(attr).encode()))
162+
} else {
163+
field.ident.as_ref().map(|ident| {
164+
format!(
165+
"{}:",
166+
simd_json::OwnedValue::from(self.rename_all.apply(&ident.to_string())).encode()
167+
)
168+
})
169+
}
165170
}
166171
}

0 commit comments

Comments
 (0)