korken89 / smlang-rs

A State Machine Language DSL procedual macro for Rust
Apache License 2.0
203 stars 28 forks source link

Add custom attributes for States and Events enum #88

Closed prabhpreet closed 3 months ago

prabhpreet commented 3 months ago

Use states_attr and events_attr to add custom attributes (eg. #[allow(...)])

Example:

#![deny(non_camel_case_types)]
    statemachine! {
        transitions: {
            *State1 + tostate2 = State2,
            State2 + tostate3 / increment_count = State3
        },
        derive_states: [Debug, Clone, Copy],
        states_attr: #[non_exhaustive] #[repr(u8)],
        events_attr: #[derive(Debug)] #[allow(non_camel_case_types)]
    }
prabhpreet commented 3 months ago

I would prefer if we just completely replaced the derive_* fields and replaced them with these *_attributes fields instead. Having them spread across different implementations seems messy.

I agree this is better, I'll remove the derive_* fields, will be a breaking change

Alternatively, are there some common-sense attributes that you think should be applied to states/events?

My motivation was to customize the structs when serializing using serde. Since this is also targeted towards no_std, maybe it is better for the users to decide?

ryan-summers commented 3 months ago

Breaking changes are fine. We've done lots of them recently, and I try to release as often as required :) The migration tends to be quite easy.

prabhpreet commented 3 months ago

@ryan-summers Made the changes including tests, and docs, please feel free to review/edit