-
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
Enum enrichment #172
base: main
Are you sure you want to change the base?
Enum enrichment #172
Conversation
@luukvanderduim I think we should first use serde in places where it is currently missing, and then use strum for what is left. Right now you have added strum as a required dependency, which is not good. |
Although I do sympathize with you wanting to keep accesskit's dependency tree small, I think this is a very small ask here. Again, I'm fine restricting the use of large libraries going forward, since Odilia has a similar problem with a massive number of dependencies. But I think this is an incredibly small addition which decreases manual maintenance by a large amount: serialization is the vast majority of what Additionally, the new |
In the issue discussion we had earlier: So I am a bit confused to see that you do in the end wish to use serde. |
@luukvanderduim sorry if I wasn't clear: I was refering to an upcoming use case for which the needs are not yet fully defined, but could require the use of With #174 I started removing some manual implementations of the |
Users do not need to know AT-SPI2 to use our event stream. They receive converted user facing types. I have dabbled with the idea to:
This way we could elide copying body data, creating, possibly allocating on each event. (but it may be the compiler is smart enough to see we aren't using the map or the string..)
We find
|
I know all of this, in fact I brought
I don't know what you are refering to. Can you please point out what you've found on AccessKit? If there is something valuable to add here, I'll gladly do it. |
Good. I hope you found the summary palatable. As for as
I meant the scheme with spaces. /// Object is a label indicating the keyboard accelerators for the parent.
#[strum(serialize = "accelerator label")]
AcceleratorLabel, [edit: The signal is an EventBody, my bad] |
For the
So you are talking about the value we are supposed to return from the |
Completely agree. Localization shouldn't be done by sending messages over DBus. |
Yes, of course.
I think I understand. We cannot have that in one
I did not know you had the strings there for that purpose. I think GNOME people need little convincing as it is currently only said to be used for roles outside of the enumeration and itś removal is eluded to in the specs: <!--
GetRoleName:
Gets a UTF-8 string corresponding to the name of the role played by an object.
This method will return useful values for roles that fall outside the
enumeration used in the GetRole method. Implementing this method is
optional, and it may be removed in a future version of the API.
Libatspi will only call id in the event of an unknown role.
--> |
Nice find, Luuk! Good to know. |
There is no need to have the same dependency twice as `[dev-dependencies]` is the sum of `[dependencies]` and what it adds.
We are exploring deriving simple functionality on public enums using strum.
- Remove consts as we cannot use these inside the attribute macros anyway. (likely because these are expanded after proc macros get run.) - Make up for loss of consts by adding tests for each. Note that this does not include strum::FromRepr because the representation differs from what is used on the bus, this makes the internal representatation meaningless to users. Instead I implemented FromStr, which makes more sense. Because of internal representation and bus representations iffer, we need custom Serialize and Deserialize implementations. Note that the Deserializer received a small optimization. No longer is the interface string required to be copied to stack before converting it to an `Interface`, instead the `Deserialize` implementation now takes a reference to the string and converts it. This also expands tests to cover the changes.
RelationType is now also checked with zbus_lockstep. As a consequence the type validation document is updated too.
`FromRepr`, `Display`, `IntoStaticStr` and `EnumIter` I changed two variants that stood out odd: `Role::Editbar` -> `Role::EditBar` ``Role::CHART` -> `Role::Chart` In the case of `EditBar`, this means it is now displayed as "edit bar" instead of "editbar". If this raises concerns, please inform me why. the `EnumIter` may be useful in tests. That being said, this enum has a simple `u32` representation. fSo checking whether each gets serialized and deserialized feels overly cautious because `zvariant` is surely able to (de)serialize these. In other words, it is not our concern to test that. We added no logic to get this done. Same goes for `&'static str` matching with the `Display` impl. It does not hurt to test, but it is not our responsibility.
Clipyp suggests not to index in the match argument. Using `strip_prefix` exits early or hands the match string to `match`. The indexing pattern ``` &match_me[prefix.len()..] {} ``` May be more expensive becaus it requires a bounds check and requires panic code to go alongside. (TIL)
`FromRepr`, `Display`, `IntoStaticStr` now implemented for - `Live` - `ScrollType` - `Layer` - `Granularity` - `ClipType` - `CoordType` - `MatchType` - `TreeTraversalType` - `SortOrder` These _currently use 'snake_case' character translations, but we can pick some other scheme. I would really like some feedback and thoughts here. The derive macros are now found just above the type instead of above the comments. This makes it easier to see which implementations a type has derived, especially if the docs on the type are more than just a few lines.
Use `from_repr() -> Role` instead of `From<i32> for Role`. Remove import for a single use of `Hash`.
- Adds notes tp clarify peculiarities found when revisiting this module. - Adds strum derives `IntoStaticStr`, `Display` and `FromRepr`
Sorry @luukvanderduim I missed your last comment. I think we are both on the same track now! It's not clear what's the solution for me either, maybe we should open a new issue to explore how to improve the event types. But I really think we can go quite far by making full use of serde, without introducing strum. |
You may be right, @DataTriny , but I think having an optional dependency makes sense here. |
After making |
@TTWNO I'm definitely not advocating for ditching all the work already done by @luukvanderduim with this PR. Maybe strum will be necessary to fully support features such as fine-grained event filtering. But I think we need to first modify our types to make full use of serde, then we can revisit this PR and possibly add strum as an optional dependency if it is only useful to AT-SPI clients for instance. strum might be just one dependency, but it adds more procedural macros, which hurt compile times. Since we already have quite a few in the Rust accessibility stack, I think we should try to avoid it where we can. |
…o-impl for BusProperties
Cargo format Clippy
1. BusProperties. This contains static information about the DBus properties of a particular event type. This is implemented for indivudal event types only and is NOT object safe; it is similar to GenericEvent, but without path() and sender() functions. - DBUS_MEMBER - DBUS_INTERFACE - MATCH_RULE_STRING - REGISTRY_EVENT_STRING - type Body - build() function 2. EventTypeProperties. This is an object-safe trait that specifies similar data as BusProperties, but as runtime functions instead of constants. This will be implemented on individual event types, and wrapper types like `Event`. - member() -> &'static str - interface() -> &'static str - match_rule() -> &'static str - registry_string() -> &'static str - EventProperties is blanket implemented for any type that implenents BusPropeties. 3. EventProperties. This is an object-safe trait specifying qualities of a particular event, not its type. - name() -> BusName<'_> - path() -> ObjectPath<'_> - object_ref() -> ObjectRef (auto-impl) This fixes #176, addresses, at least in part #148.
Whoopsie
fmt Fix tests
All objects in any server's tree implements the `Accessible` interface. Bringing `ObjectRefExt` into scope allows users to call `as_accessible_proxy` on any `ObjectRef` to obtain an `AccessibleProxy` from the `ObjectRef`.
Makes the trait public In the trait definition, adds the send bound in the impl, resuggars the impl
Yeah, I shouldn't merge with |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #172 +/- ##
==========================================
+ Coverage 83.74% 87.27% +3.53%
==========================================
Files 39 39
Lines 3112 3451 +339
==========================================
+ Hits 2606 3012 +406
+ Misses 506 439 -67 ☔ View full report in Codecov by Sentry. |
Curious if this would work for you? We've fully feature-gated Let me know. |
@TTWNO Thanks for all the efforts you put into this! Unfortunately this PR seem to contain way too many unrelated changes for me to review right now, but I checked that indeed the common crate can compile without the strum feature. However you have tied it to the features for async runtime selection, which mean that AccessKit would still pull in strum as we use a few proxies from atspi-proxies. Is this a requirement, or could an async executor be enabled without strum? |
@DataTriny right now, any use of Does accesskit use these implementations? If not, we can add a separate feature flag for the message conversions; separate from zbus support in proxies. |
No we currently don't use these, although I was eventually planning on doing so. If feature-gating these convertions is the only way forward, I'm fine with what you propose. |
If you intend on using the If not, does that mean that you will write your own |
For now we create messages to emit signals by hand. Since the code is already there I will probably leave it as is if relying on atspi would bring strum. |
This commit hopes to address (in part) #157
Adds strum and derives
Display
,FromRepr
andIntoStaticStr
on public enums (where this makes sense).FromRepr
addsT::from_repr(U)
whereU
is the underlying type of the enum.FromStaticStr
implementsFrom<Enum> for &static str
(implicitlyInto
too).Display
implementsDisplay
(implicitly doesToString
)nit: I do not like how adding the derives causes the
#[derive( .. )]
span several lines.With this PR, the
Interface
'sDeserialize
implementation avoids copying the string, thus may have become a little bit faster for what that is worth.Various other changes and added tests. Please review and scrutinize before merging.