-
Notifications
You must be signed in to change notification settings - Fork 12
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
RSDK-5770 - implement GetReadings API for all sensor types #126
RSDK-5770 - implement GetReadings API for all sensor types #126
Conversation
ae5b6ec
to
73d2f0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try to have the macro generate the body of the function instead of delegating to **_generic_readings ?
micro-rdk-macros/src/lib.rs
Outdated
let micro_rdk_crate_name = if crate_name == "micro-rdk" { | ||
"crate" | ||
} else { | ||
"micro_rdk" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work even if the micro-rdk crate has been pulled in under a different name, per https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it does not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking. I was curious and I do wonder if we are missing something about how to stably name types from a "peer" crate within a proc macro. On the other hand, I don't think we need to address it right now: I think renaming dependencies is a pretty edge-case sort of thing. Maybe a comment is warranted for now, and should it ever cause problems in the wild we can revisit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the solution here rust-lang/rust#54363 (comment) might work even if the crate is renamed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this doesn't work then we need to keep a ticket to track this. I agree it's not major but it can be a pain point in the future
let gen = quote! { | ||
impl #impl_generics DoCommand for #name #ty_generics #where_clause {} | ||
impl #impl_generics #crate_ident::common::generic::DoCommand for #name #ty_generics #where_clause {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this one too.
src/common/sensor.rs
Outdated
@@ -108,3 +126,19 @@ impl Status for FakeSensor { | |||
})) | |||
} | |||
} | |||
|
|||
impl From<f64> for Value { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These seem more generic than simply being Sensor related. Is there a better home for them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually meant to remove these, sorry. I don't think it's saving that much effort
@npmenard I initially did this. However, I had the thought that the convenience function is useful to someone implementing a movement sensor or power sensor module who wanted to take the readings returned by the standard implementation and simply add to it in their |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm happy with either implementing via proc-macro-crate
in this review, or deferring any solution into a ticket with a TODO comment in this review.
71bc07f
to
6f86530
Compare
also includes improvement for DoCommand macro such that only the macro needs to be imported when someone needs to use it (you don't need to also import the DoCommand trait)