Skip to content

Commit

Permalink
Merge branch 'master' into update-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel7grant authored Apr 1, 2024
2 parents a4ecdc4 + 55ff184 commit 45dca71
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 57 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ jobs:
name: Test examples with ${{ matrix.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: ${{ matrix.version }}
override: true
- uses: actions-rs/cargo@v1
with:
command: test
args: --examples
- run: cargo test --examples
6 changes: 2 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: stable
override: true
- name: Hack publish-crates to not fail on paths
run: |
sed 's/, path = ".*"//' -i Cargo.toml
Expand Down
21 changes: 6 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@ jobs:
name: Check and test on ${{ matrix.os }} with ${{ matrix.version }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/toolchain@v1
- uses: dtolnay/rust-toolchain@stable
with:
profile: minimal
toolchain: ${{ matrix.version }}
override: true
- uses: actions-rs/cargo@v1
with:
command: check
- run: rustup component add clippy
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
- uses: actions-rs/cargo@v1
with:
command: test
components: clippy
- run: cargo check
- run: cargo clippy -- -D warnings
- run: cargo test
17 changes: 14 additions & 3 deletions redis-macros-derive/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 10 additions & 27 deletions redis-macros-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::{
parenthesized,
parse::{Parse, ParseStream},
parse_macro_input, token, Attribute, DeriveInput, GenericParam, Result,
};

struct ParseParenthesed {
_p: token::Paren,
field: TokenStream2,
}

impl Parse for ParseParenthesed {
fn parse(input: ParseStream) -> Result<Self> {
let content;
Ok(ParseParenthesed {
_p: parenthesized!(content in input),
field: content.parse()?,
})
}
}
use quote::{quote, ToTokens};
use syn::{parse_macro_input, Attribute, DeriveInput, Expr, GenericParam};

fn get_serializer(attrs: Vec<Attribute>, default: &str) -> TokenStream2 {
let default_token = default.parse::<TokenStream2>().unwrap();

attrs
.into_iter()
.find(|a| a.path.segments.len() == 1 && a.path.segments[0].ident == "redis_serializer")
.map(|Attribute { tokens, .. }| {
let tokens = tokens.into();
let ParseParenthesed { field, .. } = parse_macro_input!(tokens as ParseParenthesed);
field.into()
.find(|attr| attr.path().is_ident("redis_serializer"))
.and_then(|attr| {
let Ok(Expr::Path(path)) = attr.parse_args::<Expr>() else {
return None;
};

Some(TokenStream2::from(path.to_token_stream()))
})
.unwrap_or(default_token.into())
.into()
}

/// Derive macro for the redis crate's [`FromRedisValue`](../redis/trait.FromRedisValue.html) trait to allow parsing Redis responses to this type.
Expand Down

0 comments on commit 45dca71

Please sign in to comment.