Skip to content

Commit

Permalink
Merge pull request #2 from jerusdp:gortavoher/edition-dependencies
Browse files Browse the repository at this point in the history
Gortavoher/edition-dependencies
  • Loading branch information
gortavoher committed Dec 27, 2023
2 parents f7fe105 + 5eb9be5 commit 17435ab
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 60 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["dynomite", "dynomite-derive"]
members = ["dynomite", "dynomite-derive"]
resolver = "2"
4 changes: 2 additions & 2 deletions dynomite-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
documentation = "https://docs.rs/dynomite-derive"
homepage = "https://github.com/softprops/dynomite"
repository = "https://github.com/softprops/dynomite"
edition = "2018"
edition = "2021"

[badges]
coveralls = { repository = "softprops/dynomite" }
Expand All @@ -20,6 +20,6 @@ proc-macro = true

[dependencies]
quote = "^1.0"
syn = "^1.0"
syn = "2.0.43"
proc-macro2 = "^1.0"
proc-macro-error = "1.0"
9 changes: 6 additions & 3 deletions dynomite-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use attr::{EnumAttr, EnumAttrKind, FieldAttr, FieldAttrKind, VariantAttr};

use proc_macro::TokenStream;
use proc_macro2::Span;
use proc_macro_error::{abort, ResultExt};
use proc_macro_error::abort;
use quote::{quote, ToTokens};
use syn::{
parse::Parse, punctuated::Punctuated, Attribute, DataStruct, DeriveInput, Field, Fields, Ident,
Expand All @@ -49,6 +49,7 @@ struct Variant {

impl Variant {
fn deser_name(&self) -> String {
#[allow(clippy::unnecessary_find_map)]
self.attrs
.iter()
.find_map(|it| match &it.kind {
Expand Down Expand Up @@ -99,6 +100,7 @@ impl DataEnum {
}

fn tag_key(&self) -> String {
#[allow(clippy::unnecessary_find_map)]
self.attrs
.iter()
.find_map(|attr| match &attr.kind {
Expand Down Expand Up @@ -293,7 +295,8 @@ fn parse_attrs<A: Parse>(all_attrs: &[Attribute]) -> Vec<A> {
.filter(|attr| is_dynomite_attr(attr))
.flat_map(|attr| {
attr.parse_args_with(Punctuated::<A, Token![,]>::parse_terminated)
.unwrap_or_abort()
// .unwrap_or_abort()
.unwrap()
})
.collect()
}
Expand Down Expand Up @@ -813,5 +816,5 @@ fn get_key_struct(
}

fn is_dynomite_attr(suspect: &syn::Attribute) -> bool {
suspect.path.is_ident("dynomite")
suspect.path().is_ident("dynomite")
}
18 changes: 9 additions & 9 deletions dynomite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
documentation = "https://docs.rs/dynomite"
homepage = "https://github.com/softprops/dynomite"
repository = "https://github.com/softprops/dynomite"
edition = "2018"
edition = "2021"
categories = ["database"]

[badges]
Expand All @@ -25,22 +25,22 @@ futures = "0.3"
log = "0.4"
# Disable default features since the `rustls` variant requires it. We re-enable `default` in our
# `default` build configuration - see the [features] below.
rusoto_core = { version = "0.47", optional = true, default_features = false }
rusoto_dynamodb = { version = "0.47", optional = true, default_features = false }
uuid = { version = "0.8", features = ["v4"], optional = true }
rusoto_core = { version = "0.48.0", optional = true, default_features = false }
rusoto_dynamodb = { version = "0.48.0", optional = true, default_features = false }
uuid = { version = "1.6.1", features = ["v4"], optional = true }
chrono = { version = "0.4", optional = true }

[dev-dependencies]
env_logger = "0.8"
env_logger = "0.10.1"
maplit = "1.0"
serde = "1.0"
serde_json = "1.0"
tokio = { version = "1", features = ["macros"] }
lambda_http = { git = "https://github.com/awslabs/aws-lambda-rust-runtime/", branch = "master"}
lambda_http = "0.9.0"
trybuild = "1.0"
rustversion = "1.0"
dynomite-derive = { version = "0.10.0", path = "../dynomite-derive" } # required by trybuild
pretty_assertions = "0.7"
pretty_assertions = "1.4.0"

[features]
default = [
Expand All @@ -51,7 +51,7 @@ default = [
"rusoto_dynamodb",
# Enable the `default` features of these crates.
"rusoto_core/default",
"rusoto_dynamodb/default"
"rusoto_dynamodb/default",
]

rustls = [
Expand All @@ -61,6 +61,6 @@ rustls = [
"rusoto_core",
"rusoto_dynamodb",
"rusoto_core/rustls",
"rusoto_dynamodb/rustls"
"rusoto_dynamodb/rustls",
]
derive = ["dynomite-derive"]
4 changes: 2 additions & 2 deletions dynomite/examples/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use dynomite::{
retry::Policy,
Retries,
};
use lambda_http::{handler, lambda_runtime};
use lambda_http::service_fn;

type Error = Box<dyn std::error::Error + Send + Sync + 'static>;

#[tokio::main]
async fn main() -> Result<(), Error> {
let client = DynamoDbClient::new(Default::default()).with_retries(Policy::default());

lambda_runtime::run(handler(move |_, _| {
lambda_http::run(service_fn(move |_| {
let client = client.clone();
async move {
let tables = client
Expand Down
9 changes: 5 additions & 4 deletions dynomite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl<T: IntoAttributes + FromAttributes> Attribute for T {
impl Attribute for Uuid {
fn into_attr(self) -> AttributeValue {
AttributeValue {
s: Some(self.to_hyphenated().to_string()),
s: Some(self.hyphenated().to_string()),
..AttributeValue::default()
}
}
Expand Down Expand Up @@ -1139,9 +1139,10 @@ mod test {
#[cfg(feature = "chrono")]
fn chrono_datetime_fixedoffset_attr() {
use chrono::offset::TimeZone;
let value = FixedOffset::east(5 * 3600)
.ymd(2015, 2, 18)
.and_hms(23, 16, 9);
let value = FixedOffset::east_opt(5 * 3600)
.unwrap()
.with_ymd_and_hms(2015, 2, 18, 23, 16, 9)
.unwrap();
assert_eq!(
Ok(value),
DateTime::<FixedOffset>::from_attr(value.into_attr())
Expand Down
9 changes: 2 additions & 7 deletions dynomite/tests/integration/derived.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ pub struct Author {
name: String,
}

#[derive(Attribute, PartialEq, Debug, Clone)]
#[derive(Attribute, PartialEq, Debug, Default, Clone)]
pub enum Category {
#[default]
Foo,
}

impl Default for Category {
fn default() -> Self {
Category::Foo
}
}

#[derive(Item, Default, PartialEq, Debug, Clone)]
pub struct Book {
#[dynomite(partition_key)]
Expand Down
4 changes: 2 additions & 2 deletions dynomite/trybuild-tests/fail/fat-enum-without-tag.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: #[derive(Attributes)] for fat enums must have a sibling #[dynomite(tag = "key")] attribute to specify the descriptor field name.

= note: Only internally tagged enums are supported in this version of dynomite.
= note: Only internally tagged enums are supported in this version of dynomite.

--> $DIR/fat-enum-without-tag.rs:4:10
--> trybuild-tests/fail/fat-enum-without-tag.rs:4:10
|
4 | pub enum MyEnum {
| ^^^^^^
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dynomite::{Attributes};
use dynomite::Attributes;

#[derive(Attributes)]
struct Test1 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
error: expected identifier
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:5:38
error: proc-macro derive panicked
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:3:10
|
5 | #[dynomite(skip_serializing_if = "true")]
| ^^^^^^
3 | #[derive(Attributes)]
| ^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: Error("expected identifier, found keyword `true`")

error: expected identifier
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:11:38
|
11 | #[dynomite(skip_serializing_if = "2 + 2")]
| ^^^^^^^
error: proc-macro derive panicked
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:9:10
|
9 | #[derive(Attributes)]
| ^^^^^^^^^^
|
= help: message: called `Result::unwrap()` on an `Err` value: Error("expected identifier")

error: expected identifier
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:17:38
error: proc-macro derive panicked
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:15:10
|
15 | #[derive(Attributes)]
| ^^^^^^^^^^
|
17 | #[dynomite(skip_serializing_if = "|| true")]
| ^^^^^^^^^
= help: message: called `Result::unwrap()` on an `Err` value: Error("expected identifier")

error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:23:38
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:23:38
|
21 | #[derive(Attributes)]
| ---------- supplied 1 argument
| ---------- unexpected argument of type `&u32`
22 | struct Test4 {
23 | #[dynomite(skip_serializing_if = "invalid_fn")]
| ^^^^^^^^^^^^ expected 0 arguments
| ^^^^^^^^^^^^
|
note: function defined here
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:27:4
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:27:4
|
27 | fn invalid_fn() -> bool {
| ^^^^^^^^^^

error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:33:38
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:33:38
|
31 | #[derive(Attributes)]
| ---------- supplied 1 argument
| ---------- unexpected argument of type `&u32`
32 | struct Test5 {
33 | #[dynomite(skip_serializing_if = "module::invalid_fn_in_module")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 0 arguments
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: function defined here
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:38:19
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:38:19
|
38 | pub(super) fn invalid_fn_in_module() {}
| ^^^^^^^^^^^^^^^^^^^^

error[E0600]: cannot apply unary operator `!` to type `()`
--> $DIR/incorrect-fn-path-in-skip-serializing-if.rs:31:10
--> trybuild-tests/fail/incorrect-fn-path-in-skip-serializing-if.rs:31:10
|
31 | #[derive(Attributes)]
| ^^^^^^^^^^ cannot apply unary operator `!`
Expand Down
14 changes: 9 additions & 5 deletions dynomite/trybuild-tests/fail/item-not-on-struct-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
error[E0774]: `derive` may only be applied to structs, enums and unions
--> $DIR/item-not-on-struct-fail.rs:7:1
|
7 | #[derive(dynomite_derive::Item)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s
--> trybuild-tests/fail/item-not-on-struct-fail.rs:7:1
|
7 | #[derive(dynomite_derive::Item)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not applicable here
8 | / fn fail() {
9 | | println!("This should fail");
10 | | }
| |_- not a `struct`, `enum` or `union`
4 changes: 2 additions & 2 deletions dynomite/trybuild-tests/fail/non-unique-fat-enum-tags.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Duplicate tag name detected: `Bar`

= help: Please ensure that no `rename = "tag_value"` clauses conflict with each other and remaining enum variants' names
= help: Please ensure that no `rename = "tag_value"` clauses conflict with each other and remaining enum variants' names

--> $DIR/non-unique-fat-enum-tags.rs:8:5
--> trybuild-tests/fail/non-unique-fat-enum-tags.rs:8:5
|
8 | Baz(Bar),
| ^^^

0 comments on commit 17435ab

Please sign in to comment.