Skip to content
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

Big Trait Changes #206

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open

Big Trait Changes #206

wants to merge 43 commits into from

Conversation

TTWNO
Copy link
Member

@TTWNO TTWNO commented Jun 28, 2024

Summary

Split BusProperties into the const &'static strs (still called BusProperties), and message conversion: MessageConversion (TODO: name).

All trivial events (where they contain only the field item) now implement From<ObjectRef>.

All events that implement From<ObjectRef> get their MessageConversion implementation for free (blanket impl).

Rename:

  • from_message_parts(ObjectRef, Self::Body), to
  • try_from_message_unchecked(&zbus::Message)

An additional check was added to all implementations of From<&zbus::Message> (the macro) requireing that the body signature match the event's body signature—this supplements the xisitng checks on the interface and member.

Commits

  • Split BusProperties into two traits
  • use new trait in sending event code
  • Feature gate new MessageConversion trait behind 'zbus'
  • Take zbus::Body instead of Self::Body in from_message_unchecked
  • from_message_parts_unchecked -> try_from_message_unchecked
  • Pass &Message to new try_from_message_unchecked
  • Add macro to implement From
  • Fix missing doc link
  • Auto-implement MessageConversion for trivial case.
  • Remove now unused From for EventBodyOwned
  • Use full message to check tests
  • Make sure to check signature validity before calling try_from_message_unchecked

TODO

  • Ensure Event and interface-grouped enums use _unchecked instead of TryFrom<&Message>
  • Add _unchecked variant deserialization for interface-grouped enums, which will not check the validity of the interface before continuing,

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 94.87603% with 31 lines in your changes missing coverage. Please review.

Project coverage is 84.67%. Comparing base (bfa3bc4) to head (cb70e23).

Files Patch % Lines
atspi-common/src/events/cache.rs 84.54% 17 Missing ⚠️
atspi-common/src/events/mod.rs 91.97% 11 Missing ⚠️
atspi-common/src/error.rs 0.00% 2 Missing ⚠️
atspi-connection/src/lib.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
- Coverage   87.23%   84.67%   -2.56%     
==========================================
  Files          42       43       +1     
  Lines        3595     3223     -372     
==========================================
- Hits         3136     2729     -407     
- Misses        459      494      +35     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TTWNO
Copy link
Member Author

TTWNO commented Jun 28, 2024

Shout out to our extensive tests that caught a ton of the mistakes I was making along the way! I would have forgot to add the signature check if we didn't have a test specifically that matched the interface+member but gave a blank body.

@TTWNO TTWNO requested a review from luukvanderduim July 1, 2024 02:58
Copy link
Collaborator

@luukvanderduim luukvanderduim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to know whether the 'unchecked' should be marked unsafe as well and whether we should call it unverified, unmatched because the Result seems to suggest things are checked - which they are but not all - which may be clear to us now, but future me may not have a recollection of this.

atspi-common/src/events/keyboard.rs Outdated Show resolved Hide resolved
atspi-common/src/events/mod.rs Outdated Show resolved Hide resolved
@TTWNO TTWNO force-pushed the checked-and-unchecked-tryfrom-msg branch from c8414f0 to 1443168 Compare July 3, 2024 18:08
@TTWNO
Copy link
Member Author

TTWNO commented Jul 3, 2024

Rebased on main.

Copy link
Collaborator

@luukvanderduim luukvanderduim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement over what we have.

I would like to slap a comment or warning on the unchecked and propose to rename it to something descriptive from_identified_message and add its checking sibling to the trait [try_]from_message which will do the tests. See the code review for more thoughts. I am curious to know if you think that makes sense!

atspi-common/src/events/keyboard.rs Outdated Show resolved Hide resolved
@@ -30,6 +30,32 @@ macro_rules! impl_event_properties {
};
}

/// Expands to implement From for [`crate::ObjectRef`].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the crate:: become part of the the path in the rendered docs? Does the path get expanded?
If that gets tedious in the rendered docs, you can write [ObjectRef][crate::ObjectRef] (from the top of my head)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the crate:: become part of the the path in the rendered docs?

Yes

Does the path get expanded?

No

atspi-common/src/events/mod.rs Show resolved Hide resolved
TTWNO added 23 commits July 5, 2024 12:49
- Correct interface, member and invalid body
- Correct body, interface and invalid member
The order of validation is the following when using
`Event::try_from(Message)`:

- MissingInterface
- InterfaceMatch
- MissingMember
- MemberMatch
- MissingSignature
- SignatureMatch

Or at least, that's what it should be.
THe commit makes individual implementations of `TryFrom<Message>` cohere
to the same order of validation.
- `validate_interface` (auto-impl)
- `validate_member` (auto-impl)
- `validate_body` (auto-impl)
- `try_from_validated_message_parts` (required)
	- This constructs the event from an to it with the arguments ObjectRef,Self::Body
@TTWNO TTWNO force-pushed the checked-and-unchecked-tryfrom-msg branch from 1443168 to cb70e23 Compare July 5, 2024 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants