Trait tokio_dbus::AsBody

source ·
pub trait AsBody<'de>: Sealed<'de> {
    // Required method
    fn as_body(self) -> Body<'de>;
}
Expand description

Trait for types which can be cheaply coerced into a Body.

This is used in combination with Message::with_body to allow for convenient construction of a borrowed body.

§Examples

use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .with_body(&body);

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);

Required Methods§

source

fn as_body(self) -> Body<'de>

Coerce this type into a Body.

Implementors§

source§

impl<'de> AsBody<'de> for &'de BodyBuf

Convert a borrowed BodyBuf into a Body.

§Examples

use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .with_body(&body);

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);
source§

impl<'de> AsBody<'de> for &'de mut BodyBuf

Convert a mutably borrowed BodyBuf into a Body.

§Examples

use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .with_body(&mut body);

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);
source§

impl<'de> AsBody<'de> for &Body<'de>

Convert a reference to a Body into a Body.

Since Body is cheap to clone, it doesn’t hurt to provide this coercions.

§Examples

use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .with_body(&body.as_body());

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);
source§

impl<'de> AsBody<'de> for Body<'de>

Convert a Body into a Body.

§Examples

use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .with_body(body.as_body());

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);