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

Generics Support #8

Open
jquesada2016 opened this issue Nov 17, 2021 · 10 comments
Open

Generics Support #8

jquesada2016 opened this issue Nov 17, 2021 · 10 comments

Comments

@jquesada2016
Copy link

Attempting to do the following results in an error:

#[typestate]
mod my_state {
    #[automaton]
    pub struct MyState;

    #[state]
    pub struct State1<T> {
        data: T,
    }

    trait State1 {
        fn new<T>() -> State1<T>;

        fn done(self);
    }
}

The above produces the following error:

Missing initial state. To declare an initial state you can use a function with signature like `fn f() -> T` where `T` is a declared state.rustc

This seems to tell me generics are not yet supported? If not, are there any plans for supporting generics?

@jmg-duarte
Copy link
Contributor

You're correct, generics are not yet supported, I've ran into this issue the day before your comment.
There are plans yes, I'm researching how to properly implement them and maybe review part of the crate.

@jquesada2016
Copy link
Author

Awesome! I'm working on a new Rust WASM front-end framework that uses typestates a lot, and this crate took out a massive amount of boilerplate. Those generics are the main thing I need!

@jmg-duarte
Copy link
Contributor

@jquesada2016 I've just pushed a change to the dev branch which should add support for generics!
You example expands to the following:

mod my_state {
    pub struct MyState<State: MyStateState> {
        pub state: State,
    }
    pub struct State1<T> {
        data: T,
    }
    trait State1State {
        fn new<T>() -> State1<T>;
        fn done(self);
    }
    #[doc(hidden)]
    mod __private {
        pub trait MyStateState {}
    }
    pub trait MyStateState: __private::MyStateState {}
    impl<__T: ?::core::marker::Sized> MyStateState for __T where __T: __private::MyStateState {}
    impl<T> __private::MyStateState for State1<T> {}
}

I'd be very grateful if you would help me test it by using the dev branch for development before I release the code!

@jquesada2016
Copy link
Author

You got it good sir! I'm on it now.

P.S.
Sorry for not getting a chance to create a pull request on the docs, I thought I was going to have a chance this passed weekend. That didn't happen. :/

@jquesada2016
Copy link
Author

@jmg-duarte do you need me to write tests or just give you feedback?

@jmg-duarte
Copy link
Contributor

@jmg-duarte do you need me to write tests or just give you feedback?

I won't say no to more tests, however, what I really need is feedback

@jquesada2016
Copy link
Author

@jmg-duarte generics have been working very good for me thus far! I tested it with constraints and some lifetime bounds and have had no issues thus far! Thank you again for your work!

@jmg-duarte
Copy link
Contributor

@jmg-duarte generics have been working very good for me thus far! I tested it with constraints and some lifetime bounds and have had no issues thus far! Thank you again for your work!

That's great to know! I'll be merging the branch in the near future (hopefully today!) and adding some other features (namely the export).
I'll let you know when the rc is released!

@jquesada2016
Copy link
Author

@jmg-duarte I added an issue for a problem I discovered with generics as currently implemented. I added a new issue instead of posting it here because it was a bit longer. The issue number is #27.

@jmg-duarte
Copy link
Contributor

jmg-duarte commented Dec 14, 2021

@jmg-duarte I added an issue for a problem I discovered with generics as currently implemented. I added a new issue instead of posting it here because it was a bit longer. The issue number is #27.

Hey @jquesada2016, I saw it already and had a nice draft and answer lined up but the browser had other plans 🤷‍♂️

I'll try to handle the issues you raised ASAP.

Thank you for the time spent reporting issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants