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

Enum enrichment #172

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2d29a88
remove static-assertions from dev-dependencies.
luukvanderduim Mar 15, 2024
701f880
Add strum as dependency
luukvanderduim Apr 1, 2024
3bcb82c
atspi-proxies remove serde_plain as it is not in use in this crate.
luukvanderduim Apr 2, 2024
7716ab3
Changes `Interface` to have IntoStaticStr and Display derived
luukvanderduim Apr 2, 2024
33d5a26
trailing space policing
luukvanderduim Apr 2, 2024
d13c4b3
Apply strum traits that make sense to RelationType
luukvanderduim Apr 4, 2024
c3c4720
Role received strum traits
luukvanderduim Apr 4, 2024
a7a92ef
Clippy suggestion / optimization
luukvanderduim Apr 4, 2024
84507aa
Various types gain derived strum traits
luukvanderduim Apr 5, 2024
ce4b10a
Adjust to `Role` changes
luukvanderduim Apr 5, 2024
68196c1
Adds strum derivation on `State` enum
luukvanderduim Apr 7, 2024
1a452b4
Fixup Clippy CI errors
luukvanderduim Apr 14, 2024
cbb3ca8
Fixup occurence of `Accessible` where `ObjectRef` is more appropriate
luukvanderduim Apr 14, 2024
d7c2ac0
Feature gate strum
TTWNO Apr 17, 2024
beb0a30
Fully feature gate the strum additions
TTWNO May 21, 2024
fa92a7a
fmt
TTWNO May 21, 2024
490fef2
Upgrade codecov to v4
TTWNO Apr 18, 2024
58eae45
Explicitly pass codecov token as required by v4
TTWNO Apr 18, 2024
37e6a3d
Make ObjectRef more explicit in type
TTWNO Apr 18, 2024
5d96bd3
Use from_static_str for Default implementaiton
TTWNO Apr 18, 2024
6253a90
GenericEvent -> BusProperties, GenericEvent is now an object-safe aut…
TTWNO Apr 18, 2024
97a9706
Update atspi-connection to include changes to trait names
TTWNO Apr 18, 2024
d686c3a
Update docs
TTWNO Apr 18, 2024
e8fc22b
Split GenericEvent into 3 traits
TTWNO Apr 18, 2024
54e95df
Implement EventTypeProperties and EventProperties for wrapper types
TTWNO Apr 18, 2024
b2145b3
Add tests to check for inner transparency on the Event type
TTWNO Apr 18, 2024
4d5ba89
Fix, add to docs
TTWNO Apr 18, 2024
284652d
Add additional required traits for each individual event type
TTWNO Apr 18, 2024
a9e3007
Remove stray new_events.diff file.
luukvanderduim Apr 23, 2024
2c7728a
Add object-safety comments
TTWNO Apr 25, 2024
70af88a
BusProperties::build -> from_message_parts
TTWNO Apr 25, 2024
a648d15
Obtain an `AccessibleProxy` from any `ObjectRef` with `ObjectRefExt`
luukvanderduim Apr 28, 2024
d8a2698
Changes implementation to an async trait
luukvanderduim Apr 29, 2024
4b83940
Making the trait public
luukvanderduim Apr 29, 2024
9f8fa2b
Merge branch 'main' into enum-enrichment
TTWNO May 21, 2024
ac8ece0
default_features -> default-features
TTWNO May 21, 2024
6c5ace0
Feature gate additional impls behind the 'strum' flag; make strum a d…
TTWNO May 21, 2024
682afee
Remove zbus flag in favour of re-exporting zbus if either runtime is …
TTWNO May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions atspi-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
strum = ["dep:strum"]
default = ["async-std"]
async-std = ["zbus/async-io"]
tokio = ["zbus/tokio"]
async-std = ["zbus/async-io", "strum"]
tokio = ["zbus/tokio", "strum"]

[dependencies]
enumflags2 = "0.7.7"
serde = "1.0"
static_assertions = "1.1.0"
strum = { version = "0.26", features = ["derive"], optional = true }
zbus-lockstep = "0.4.4"
zbus-lockstep-macros = "0.4.4"
zbus_names = "3.0"
Expand All @@ -30,10 +32,10 @@ zbus = { workspace = true, optional = true, default-features = false }

[dev-dependencies]
atspi-connection = { path = "../atspi-connection" }
atspi-proxies = { path = "../atspi-proxies" }
atspi-proxies = { path = "../atspi-proxies" }
rename-item = "0.1.0"
serde_plain = "1.0.1"
static_assertions = "1.1.0"
strum = { version = "0.26", features = ["derive"] }
tokio-stream = { version = "0.1", default-features = false, features = ["time"] }
tokio = { version = "1", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-test = "0.4.2"
Expand Down
3 changes: 2 additions & 1 deletion atspi-common/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod window;
// Unmarshalled event body signatures: These outline the event specific deserialized event types.
// Safety: These are evaluated at compile time.
// ----
// The signal signature "(so)" (an Accessible) is ambiguous, because it is used in:
// The signal signature "(so)" (`ObjectRef`) is ambiguous, because it is used in:
// - Cache : RemoveAccessible
// - Socket: Available *( signals the availability of the `Registry` daemon.)
//
Expand Down Expand Up @@ -227,6 +227,7 @@ pub enum Event {
Listener(EventListenerEvents),
}

#[cfg(feature = "strum")]
impl EventTypeProperties for Event {
fn member(&self) -> &'static str {
match self {
Expand Down
24 changes: 16 additions & 8 deletions atspi-common/src/events/object.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::hash::Hash;

use crate::{
error::AtspiError,
events::{BusProperties, EventBodyOwned, HasMatchRule, HasRegistryEventString, ObjectRef},
Event, EventProperties, EventTypeProperties, State,
Event, EventProperties, State,
};
#[cfg(feature = "strum")]
use crate::{EventTypeProperties, Live};
use zbus_names::BusName;
use zvariant::{ObjectPath, OwnedValue, Value};

Expand Down Expand Up @@ -56,6 +56,7 @@
TextCaretMoved(TextCaretMovedEvent),
}

#[cfg(feature = "strum")]
impl EventTypeProperties for ObjectEvents {
fn member(&self) -> &'static str {
match self {
Expand Down Expand Up @@ -236,7 +237,7 @@
pub value: Property,
}

impl Hash for PropertyChangeEvent {
impl core::hash::Hash for PropertyChangeEvent {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.item.hash(state);
self.property.hash(state);
Expand Down Expand Up @@ -307,6 +308,7 @@
}
}

#[cfg(feature = "strum")]
impl TryFrom<EventBodyOwned> for Property {
type Error = AtspiError;

Expand All @@ -329,9 +331,7 @@
.any_data
.try_into()
.map_err(|_| AtspiError::ParseError("accessible-role"))?;
let role: crate::Role = crate::Role::try_from(role_int)
.map_err(|_| AtspiError::ParseError("accessible-role"))?;
role
crate::Role::from_repr(role_int).ok_or(AtspiError::ParseError("accessible-role"))?

Check warning on line 334 in atspi-common/src/events/object.rs

View check run for this annotation

Codecov / codecov/patch

atspi-common/src/events/object.rs#L334

Added line #L334 was not covered by tests
})),
"accessible-parent" => Ok(Self::Parent(
body.any_data
Expand Down Expand Up @@ -578,6 +578,7 @@
pub position: i32,
}

#[cfg(feature = "strum")]
impl BusProperties for PropertyChangeEvent {
const DBUS_MEMBER: &'static str = "PropertyChange";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Object";
Expand Down Expand Up @@ -634,6 +635,7 @@
}
}

#[cfg(feature = "strum")]
impl BusProperties for StateChangedEvent {
const DBUS_MEMBER: &'static str = "StateChanged";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Object";
Expand Down Expand Up @@ -747,6 +749,7 @@
}
}

#[cfg(feature = "strum")]
impl BusProperties for AnnouncementEvent {
const DBUS_MEMBER: &'static str = "Announcement";
const DBUS_INTERFACE: &'static str = "org.a11y.atspi.Event.Object";
Expand All @@ -760,7 +763,8 @@
Ok(Self {
item,
text: body.any_data.try_into().map_err(|_| AtspiError::Conversion("text"))?,
live: body.detail1.try_into()?,
live: Live::from_repr(body.detail1)
.ok_or(AtspiError::Conversion("\"detail1\" not convertable to \"Live\""))?,
})
}
fn body(&self) -> Self::Body {
Expand Down Expand Up @@ -1039,6 +1043,7 @@
Event::Object
);

#[cfg(feature = "strum")]
event_test_cases!(PropertyChangeEvent);
impl_to_dbus_message!(PropertyChangeEvent);
impl_from_dbus_message!(PropertyChangeEvent);
Expand Down Expand Up @@ -1121,10 +1126,12 @@
ObjectEvents::StateChanged,
Event::Object
);
#[cfg(feature = "strum")]
event_test_cases!(StateChangedEvent);
impl_to_dbus_message!(StateChangedEvent);
impl_from_dbus_message!(StateChangedEvent);
impl_event_properties!(StateChangedEvent);
#[cfg(feature = "strum")]
impl From<StateChangedEvent> for EventBodyOwned {
fn from(event: StateChangedEvent) -> Self {
EventBodyOwned {
Expand Down Expand Up @@ -1293,6 +1300,7 @@
ObjectEvents::Announcement,
Event::Object
);
#[cfg(feature = "strum")]
event_test_cases!(AnnouncementEvent);
impl_to_dbus_message!(AnnouncementEvent);
impl_from_dbus_message!(AnnouncementEvent);
Expand Down
Loading
Loading