Skip to content

Make Any a supertrait of BaseDeviceOps, add a type-conversion-then-mapping function - #39

Merged
aarkegz merged 3 commits into
mainfrom
any_device
Jul 13, 2025
Merged

Make Any a supertrait of BaseDeviceOps, add a type-conversion-then-mapping function#39
aarkegz merged 3 commits into
mainfrom
any_device

Conversation

@aarkegz

@aarkegz aarkegz commented Jul 13, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@aarkegz
aarkegz requested review from Copilot and hky1999 July 13, 2025 10:48
@aarkegz aarkegz self-assigned this Jul 13, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR makes Any a supertrait of BaseDeviceOps and adds a helper to downcast device trait objects by concrete type, along with tests to verify the mapping.

  • Extend BaseDeviceOps with Any and enable trait_upcasting
  • Introduce map_device_of_type to perform type-checked mapping on an Arc<dyn BaseDeviceOps>
  • Add test.rs to cover the downcast-and-map behavior with DeviceA and DeviceB

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
axdevice_base/src/lib.rs Made BaseDeviceOps extend Any, imported Any, added trait-upcasting features, and implemented map_device_of_type
axdevice_base/src/test.rs Created unit test for map_device_of_type, defining DeviceA/DeviceB and validating mapping
Comments suppressed due to low confidence (3)

axdevice_base/src/test.rs:58

  • [nitpick] The test name test_device_type_test is redundant. Consider renaming it to test_map_device_of_type to clearly reflect the behavior under test.
fn test_device_type_test() {

axdevice_base/src/test.rs:65

  • Currently the test only asserts the Some case for DeviceA. It would strengthen coverage to explicitly assert that map_device_of_type returns None for non-matching types (e.g., DeviceB).
    for device in devices {

axdevice_base/src/lib.rs:59

  • [nitpick] The doc comment for map_device_of_type could be expanded to mention that it returns None when the type doesn't match and that it clones the Arc internally.
/// Determines whether the given device is of type `T` and calls the provided function `f` with a

Comment thread axdevice_base/src/lib.rs Outdated

@hky1999 hky1999 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@aarkegz
aarkegz merged commit a474580 into main Jul 13, 2025
10 checks passed
@aarkegz
aarkegz deleted the any_device branch July 13, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants