Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow slice! macro to index tuples #2598

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions leptos_macro/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use syn::{

struct SliceMacroInput {
root: syn::Ident,
path: Punctuated<syn::Ident, Token![.]>,
path: Punctuated<syn::Member, Token![.]>,
}

impl Parse for SliceMacroInput {
fn parse(input: ParseStream) -> syn::Result<Self> {
let root: syn::Ident = input.parse()?;
input.parse::<Token![.]>()?;
// do not accept trailing punctuation
let path: Punctuated<syn::Ident, Token![.]> =
let path: Punctuated<syn::Member, Token![.]> =
Punctuated::parse_separated_nonempty(input)?;

if path.is_empty() {
Expand Down
7 changes: 5 additions & 2 deletions leptos_macro/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ pub struct OuterState {
#[derive(Clone, PartialEq, Default)]
pub struct InnerState {
inner_count: i32,
inner_name: String,
inner_tuple: InnerTuple,
}

#[derive(Clone, PartialEq, Default)]
pub struct InnerTuple(String);

#[test]
fn green() {
let _ = create_runtime();
Expand All @@ -22,7 +25,7 @@ fn green() {
let (_, _) = slice!(outer_signal.count);

let (_, _) = slice!(outer_signal.inner.inner_count);
let (_, _) = slice!(outer_signal.inner.inner_name);
let (_, _) = slice!(outer_signal.inner.inner_tuple.0);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions leptos_macro/tests/slice/red.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ error: expected `.`
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:25:18
|
25 | let (_, _) = slice!(outer_signal.);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `slice` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected end of input, expected identifier
error: unexpected end of input, expected identifier or integer
--> tests/slice/red.rs:27:18
|
27 | let (_, _) = slice!(outer_signal.inner.);
Expand Down
Loading