leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.31k stars 599 forks source link

Allow slice! macro to index tuples #2598

Closed SleeplessOne1917 closed 1 month ago

SleeplessOne1917 commented 1 month ago

Currently, the slice! macro breaks when trying to index a tuple. Example:

use leptos::*;

#[derive(Clone, PartialEq, Eq)]
struct PostView {
    pub post: Post,
    pub creator: String
}

#[derive(Clone, PartialEq, Eq)]
struct Post {
    pub body: String,
    pub id: PostId
}

#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct PostId(pub i32);

let post = RwSignal::new(
    PostView {
        creator: "Bob".to_owned(),
        post: Post {
            body: "Hello World!!!".to_owned(),
            id: PostId(42)
        }
    }
);

let id = slice!(post.post.id.0); // Does not compile!

This change allows both identifiers and tuple indices to be used.

gbj commented 1 month ago

Thanks! The leptos_macro/tests/ui tests that you changed are unrelated to the changes in this PR, I think, and your changes appear to cause the tests in CI to fail. Could you revert those changes?

(There may be a version mismatch between the compiler you're running them against locally and the compiler version running in CI, which would account for the different error messages maybe)

SleeplessOne1917 commented 1 month ago

@gbj I fixed the issue you pointed out. No clue why the semver step and the hacker new js fetch step are both failing.

gbj commented 1 month ago

It's okay they are failing on main and I just haven't had time recently to look into it. Thanks very much, this looks good.