这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@qwandor
Copy link
Collaborator

@qwandor qwandor commented Jan 6, 2021

This includes my addition diwic/dbus-rs#304 to add type-safe property parsing, which makes things a bit neater.

Fixes #9.

@qwandor qwandor requested a review from alsuren January 6, 2021 21:53
Base automatically changed from tokio10 to master January 7, 2021 14:03
pub fn supported_includes(&self) -> Option<&Vec<String>> {
arg::prop_cast(self.0, "SupportedIncludes")
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

I feel like this PR validates our earlier decision to make a bluez-generated crate that only contains generated code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Generating it as part of a build.rs would also work, but this is simpler in some ways.

.unwrap()
.to_string()
});
let device_properties = OrgBluezDevice1Properties::from_interfaces(&interfaces)?;
Copy link
Owner

Choose a reason for hiding this comment

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

(mostly rambling and probably re-hashing the discussion from your upstream PR, so feel free to ignore me)

I feel like it's a bit surprising that device_properties owns a reference into interfaces, but I guess it is efficient and device_properties will typically be short-lived, so it's probably fine (I also can't think of a better way to do it).

I suppose if you were only asking for a single property then you'd be using a fluent interface (OrgBluezDevice1Properties::from_interfaces(&interfaces)?.address()?) and it would not be surprising at all.

I suppose if OrgBluezDevice1Properties was a trait with a blanket impl over &'a ::std::collections::HashMap<String, arg::PropMap> then it could be written OrgBluezDevice1Properties::address(&interfaces), but people would be tempted to use OrgBluezDevice1Properties and write interfaces.address()? which might be a bit fragile.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it looks a little weird, but seems to work well in practice so far. The other issue with the trait approach is that I want from_interfaces to return something that can be passed around, which is a bit of a pain if it's a trait object.

Note that from_intefaces is doing one level of HashMap lookup, and address() is doing a second level.

.iter()
.filter_map(|(k, v)| match Uuid::parse_str(k) {
Ok(uuid) => {
let v = cast::<Vec<u8>>(&v.0)?;
Copy link
Owner

Choose a reason for hiding this comment

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

(optional) should we be noisier if this cast fails?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a warning log.

@qwandor qwandor merged commit 73f3666 into master Jan 7, 2021
@qwandor qwandor deleted the propertyparser2 branch January 7, 2021 19:00
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.

Generate strongly typed deserialiser for get_managed_objects() variants.

3 participants