Skip to content

Commit

Permalink
Add fix for re-exporting serde.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Harrison committed Dec 21, 2021
1 parent e0be2e8 commit 2661f88
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ pub use sm_macro::sm;

/// Re-export the serde Serialize and Deserialize derive macros.
#[doc(hidden)]
pub use ::serde::{Serialize, Deserialize};
pub use ::serde::{self, Serialize, Deserialize};

/// State is a custom [marker trait][m] that allows [unit-like structs][u] to be
/// used as states in a state machine.
Expand Down
4 changes: 4 additions & 0 deletions sm_macro/src/sm/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ impl ToTokens for Event {

tokens.extend(quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct #name;
impl Event for #name {}
});
Expand Down Expand Up @@ -85,6 +86,7 @@ mod tests {

let left = quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Push;
impl Event for Push {}
};
Expand All @@ -108,6 +110,7 @@ mod tests {

let left = quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Push;
impl Event for Push {}

Expand All @@ -124,6 +127,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Coin;
impl Event for Coin {}

Expand Down
14 changes: 14 additions & 0 deletions sm_macro/src/sm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl ToTokens for Machine {
use sm::{AsEnum, Event, InitialState, Initializer, Machine as M, NoneEvent, State, Transition, Serialize, Deserialize};

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Machine<S: State, E: Event>(S, Option<E>);

impl<S: State, E: Event> M for Machine<S, E> {
Expand Down Expand Up @@ -329,6 +330,7 @@ mod tests {
use sm::{AsEnum, Event, InitialState, Initializer, Machine as M, NoneEvent, State, Transition, Serialize, Deserialize};

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Machine<S: State, E: Event>(S, Option<E>);

impl<S: State, E: Event> M for Machine<S, E> {
Expand All @@ -353,6 +355,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Unlocked;
impl State for Unlocked {}

Expand All @@ -369,6 +372,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Locked;
impl State for Locked {}

Expand All @@ -388,6 +392,7 @@ mod tests {
impl InitialState for Locked {}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Push;
impl Event for Push {}

Expand Down Expand Up @@ -624,6 +629,7 @@ mod tests {
use sm::{AsEnum, Event, InitialState, Initializer, Machine as M, NoneEvent, State, Transition, Serialize, Deserialize};

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Machine<S: State, E: Event>(S, Option<E>);

impl<S: State, E: Event> M for Machine<S, E> {
Expand All @@ -648,6 +654,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Locked;
impl State for Locked {}

Expand All @@ -664,6 +671,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Unlocked;
impl State for Unlocked {}

Expand All @@ -683,6 +691,7 @@ mod tests {
impl InitialState for Unlocked {}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Coin;
impl Event for Coin {}

Expand All @@ -699,6 +708,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Push;
impl Event for Push {}

Expand Down Expand Up @@ -776,6 +786,7 @@ mod tests {
use sm::{AsEnum, Event, InitialState, Initializer, Machine as M, NoneEvent, State, Transition, Serialize, Deserialize};

#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Machine<S: State, E: Event>(S, Option<E>);

impl<S: State, E: Event> M for Machine<S, E> {
Expand All @@ -800,6 +811,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Locked;
impl State for Locked {}

Expand All @@ -816,6 +828,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Unlocked;
impl State for Unlocked {}

Expand All @@ -835,6 +848,7 @@ mod tests {
impl InitialState for Unlocked {}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct TurnKey;
impl Event for TurnKey {}

Expand Down
4 changes: 4 additions & 0 deletions sm_macro/src/sm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl ToTokens for State {

tokens.extend(quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct #name;
impl State for #name {}
});
Expand Down Expand Up @@ -95,6 +96,7 @@ mod tests {

let left = quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Unlocked;
impl State for Unlocked {}
};
Expand All @@ -118,6 +120,7 @@ mod tests {

let left = quote! {
#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Locked;
impl State for Locked {}

Expand All @@ -134,6 +137,7 @@ mod tests {
}

#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize)]
#[serde(crate = "sm::serde")]
pub struct Unlocked;
impl State for Unlocked {}

Expand Down

0 comments on commit 2661f88

Please sign in to comment.