Make Any a supertrait of BaseDeviceOps, add a type-conversion-then-mapping function - #39
Merged
Conversation
…n mapping function
There was a problem hiding this comment.
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
BaseDeviceOpswithAnyand enabletrait_upcasting - Introduce
map_device_of_typeto perform type-checked mapping on anArc<dyn BaseDeviceOps> - Add
test.rsto cover the downcast-and-map behavior withDeviceAandDeviceB
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_testis redundant. Consider renaming it totest_map_device_of_typeto clearly reflect the behavior under test.
fn test_device_type_test() {
axdevice_base/src/test.rs:65
- Currently the test only asserts the
Somecase forDeviceA. It would strengthen coverage to explicitly assert thatmap_device_of_typereturnsNonefor non-matching types (e.g.,DeviceB).
for device in devices {
axdevice_base/src/lib.rs:59
- [nitpick] The doc comment for
map_device_of_typecould be expanded to mention that it returnsNonewhen the type doesn't match and that it clones theArcinternally.
/// Determines whether the given device is of type `T` and calls the provided function `f` with a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.