Comments (6)
Is something similar possible in Rust with this dbus library?
Not currently, but that's mostly because nobody has implemented it yet. One problem is that Rust is torn between the older "rustcserialize" and the newer "serde", and I have had problems making up my mind w r t which one to support (or both).
Or is iterating through the individual message arguments really the idiomatic way?
Yes - that's basically what you do - or use get1
, get2
, or get3
, but you would need a get6
so it doesn't work for you.
What looks a bit inconsistent in your code is that you return a Option<ServiceBrowserItemNew>
but there is no way to return None
from the function - instead you panic on message not matching.
Whether to unwrap or to do proper error handling is up to you, but this seems like a mix.
You do raise a valid point in that this could be done in a more ergonomic way. I'll give this a thought.
from dbus-rs.
Ok, so I've added an iter::read
method now. Using it your code would look like:
fn service_browser_item_new_msg(m: &dbus::Message) -> Result<ServiceBrowserItemNew, TypeMismatchError> {
let mut iter = m.iter_init();
Ok(ServiceBrowserItemNew {
interface: try!(iter.read()),
protocol: try!(iter.read()),
name: try!(iter.read::<&str>()).into(),
item_type: try!(iter.read::<&str>()).into(),
domain: try!(iter.read::<&str>()).into(),
flags: try!(iter.read()),
})
}
Could you give it a try and see if it works the way I expect it to? If so I might do a new release with this function in (and might even steal your struct definition and use as an example, with your permission).
from dbus-rs.
Thanks a bunch for the quick reply and fix! I’ll be happy to test that tomorrow. Do you happen to have a pointer as to how I can use the git version of your dbus library in my Cargo.toml in a way that includes the change you mentioned?
from dbus-rs.
Like this:
[dependencies]
dbus = { git = "https://github.com/diwic/dbus-rs" }
from dbus-rs.
Thanks a bunch! I can confirm that the following works for me:
fn service_browser_item_new_msg(m: &dbus::Message)
-> Result<ServiceBrowserItemNew, dbus::arg::TypeMismatchError> {
let mut iter = m.iter_init();
Ok(ServiceBrowserItemNew {
interface: try!(iter.read()),
protocol: try!(iter.read()),
name: try!(iter.read()),
item_type: try!(iter.read()),
domain: try!(iter.read()),
flags: try!(iter.read()),
})
}
Feel free to use that in the documentation.
from dbus-rs.
👍
Now released as v0.3.4.
from dbus-rs.
Related Issues (20)
- Crossroad example not working HOT 1
- `vendored` feature's build script writes outside of `$OUT_DIR` HOT 5
- async monitor? HOT 4
- monitor system bus without root privileges HOT 4
- [Help] When variant is a struct? HOT 10
- dbus-codegen: When crossroads is enabled, no client-side code is generated HOT 3
- dbus-codegen: Add attribute to specify rust type for method arguments HOT 4
- Annotations on interfaces not shown in introspection
- Any way to set uid in dbus authentication? HOT 6
- How to ensure that libdbus-sys compiles with X11 for dbus-daemon autolaunch on build HOT 4
- register object of type X on dbus? HOT 3
- pkg config failed HOT 1
- Async signal match not working HOT 2
- `dbus-codegen-rust` produces `#[deprecated]` annotations on trait implementations HOT 1
- Yank rbus-rs package on crates.io HOT 1
- Generated code from an XML file that only contains properties does not compile with crossroads HOT 4
- Make new `dbus-codegen` release
- Recompilation of libdbus-sys triggered on every cargo build HOT 2
- "Path, Interface, or Method does not exist" on startup HOT 2
- Could `from_slice_unchecked` be made `const` for the string types?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbus-rs.