typestate-rs
typestate-rs copied to clipboard
Generics Support
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?
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.
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!
@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!
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. :/
@jmg-duarte do you need me to write tests or just give you feedback?
@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
@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 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!
@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 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!