Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Reads interface files and generates bindings for the interfaces in them.

§Examples

tokio_dbus_codegen::Builder::new()
    .file("interfaces/org.kde.StatusNotifierItem.xml")
    .file("interfaces/com.canonical.dbusmenu.xml")
    .server("org.kde.StatusNotifierItem")
    .server("com.canonical.dbusmenu")
    .client("org.kde.StatusNotifierWatcher")
    .generate("systray.rs")?;

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Construct an empty builder.

Examples found in repository?
examples/dump.rs (line 11)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let mut args = std::env::args().skip(1);
9
10    let file = args.next().ok_or("Usage: dump <file.xml> <interface>...")?;
11    let mut builder = tokio_dbus_codegen::Builder::new().file(file);
12
13    for name in args {
14        builder = builder.both(name);
15    }
16
17    print!("{}", builder.to_string()?);
18    Ok(())
19}
Source

pub fn file(self, path: impl AsRef<Path>) -> Self

Read an interface file.

Every interface in the file becomes available to client(), server() and both(), including the ones in child nodes.

Examples found in repository?
examples/dump.rs (line 11)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let mut args = std::env::args().skip(1);
9
10    let file = args.next().ok_or("Usage: dump <file.xml> <interface>...")?;
11    let mut builder = tokio_dbus_codegen::Builder::new().file(file);
12
13    for name in args {
14        builder = builder.both(name);
15    }
16
17    print!("{}", builder.to_string()?);
18    Ok(())
19}
Source

pub fn client(self, interface: impl AsRef<str>) -> Self

Generate an asynchronous client for the named interface.

Source

pub fn server(self, interface: impl AsRef<str>) -> Self

Generate a server trait and dispatcher for the named interface.

Source

pub fn both(self, interface: impl AsRef<str>) -> Self

Generate both a client and a server for the named interface.

Examples found in repository?
examples/dump.rs (line 14)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let mut args = std::env::args().skip(1);
9
10    let file = args.next().ok_or("Usage: dump <file.xml> <interface>...")?;
11    let mut builder = tokio_dbus_codegen::Builder::new().file(file);
12
13    for name in args {
14        builder = builder.both(name);
15    }
16
17    print!("{}", builder.to_string()?);
18    Ok(())
19}
Source

pub fn generate(self, name: impl AsRef<Path>) -> Result<PathBuf>

Generate into $OUT_DIR/<name>, which is where a build script should put it.

This also emits a cargo::rerun-if-changed line for every interface file which was read.

Source

pub fn write_to(self, path: impl AsRef<Path>) -> Result<()>

Generate into an explicit path.

Source

pub fn to_string(&self) -> Result<String>

Generate the bindings and return them as a string.

This is what generate() and write_to() use, and is useful for inspecting the output in a test.

Examples found in repository?
examples/dump.rs (line 17)
7fn main() -> Result<(), Box<dyn std::error::Error>> {
8    let mut args = std::env::args().skip(1);
9
10    let file = args.next().ok_or("Usage: dump <file.xml> <interface>...")?;
11    let mut builder = tokio_dbus_codegen::Builder::new().file(file);
12
13    for name in args {
14        builder = builder.both(name);
15    }
16
17    print!("{}", builder.to_string()?);
18    Ok(())
19}

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Builder

Source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.