-
Notifications
You must be signed in to change notification settings - Fork 6
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
Remove manual implementation of Serialize
, Deserialize
, and From<u32>
for -common
types
#157
Comments
I am not sure I fully follow your train of thought, but I'll try. Please correct me where I go wrong.
<method name="GetRole">
<arg direction="out" type="u"/>
</method> It is unambiguously defined as a #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Type, Hash)]
/// Role docs
#[repr(u32)]
pub enum Role { I may have a problem with this one: TryFrom<u32> for Role which I think is unneeded. If you want a I also think both attribute macros should not be separated by item docs.
State
<method name="GetState">
<arg direction="out" type="au"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QSpiIntList"/>
</method> #[bitflags]
#[non_exhaustive]
#[repr(u64)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
#[serde(rename_all = "kebab-case")]
pub enum State { Note that StateSet#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
/// The bitflag representation of all states an object may have.
pub struct StateSet(BitFlags<State>); The rust It seems warranted to have tests for this. I am not sure why we'd need these though?: impl From<State> for String impl From<String> for State DBus hands us
|
Yes. This is sort of the idea I'm getting at: pub enum Interface {
#[serde(rename = ACCESSIBLE_INTERFACE_NAME)]
Accessible,
...
} Seems so much cleaner. Although, I'm not sure we can actually do this, since I think you need to type out a string literal 🤷 would be much better in either case because it removes our messing up the conversion in a match for us.
That was my original thought as well. But I see your point: if you want a string representation (with Odilia does), then you'd have to write it yourself, which seems so silly! But do we want to provide "official" translations when somebody wants a French String? (Spoiler: No!) Why not send that responsibility down to the users? I'm not sure what the right option is here. Your advice would be appreciated.
Right... That code was actually added by @DataTriny . They needed a way to convert from the number P.S. Thanks Luuk, you took my thoughts (which were not even correct!) and converted them into useful, actionable items! |
FYI in AccessKit we need textual representation of states to emit signals such as You could argue that Newton is a new thing so it should provide its own representation of such values and I would agree. |
There are a number of subjects intersecting in this thread.
The way we do it now, atleast for
I would like to add these features to all or most public facing enums so that there is consistency across the board. Also should I be missing the point(s), please help me see what is missing from above. |
I will try inside Like I said in the past, I'd prefer not to add |
Since our remaining usecase cannot be solved by serde, I'd be OK having strum as an optional dependency. |
Good, I'll do that. Side note on the dependency count, due to For reference When in future time |
Thank you Luuk, for clarifying the issue and adding important information! |
Role
has a manual implementation ofFrom<u32>
andInto<u32>
so that it can be converted to numbers easily. This should be some kind of derive macro. I noticed that we even test our implementation (because I messed it up at one point). The argument for this is that adding new ones will be easier, since the implementation'smatch
block will require us to cover all cases.Similar deal with
State
,Interface
, they have manualSerialide
andDeserialize
implementations for the same reasons. Ideally, this could just be handled. IIRC, the reason for this was that I needed constant static strings of the interfaces and states, and I couldn't use a constant static string as a value for serde's de/serialize customizations.I'll gladly close if that's still the case.
The text was updated successfully, but these errors were encountered: