[−][src]Struct a2::request::payload::Payload
The data and options for a push notification.
Fields
options: NotificationOptions<'a>
Send options
device_token: &'a str
The token for the receiving device
aps: APS<'a>
The pre-defined notification payload
data: BTreeMap<&'a str, Value>
Application specific payload
Methods
impl<'a> Payload<'a>
[src]
pub fn add_custom_data(
&mut self,
root_key: &'a str,
data: &dyn Serialize
) -> Result<&mut Self, Error>
[src]
&mut self,
root_key: &'a str,
data: &dyn Serialize
) -> Result<&mut Self, Error>
Client-specific custom data to be added in the payload.
The root_key
defines the JSON key in the root of the request
data, and data
the object containing custom data. The data
should implement Serialize
, which allows using of any Rust
collection or if needing more strict type definitions, any struct
that has #[derive(Serialize)]
from Serde.
Using a HashMap
:
let mut payload = SilentNotificationBuilder::new() .build("token", Default::default()); let mut custom_data = HashMap::new(); custom_data.insert("foo", "bar"); payload.add_custom_data("foo_data", &custom_data).unwrap(); assert_eq!( "{\"aps\":{\"content-available\":1},\"foo_data\":{\"foo\":\"bar\"}}", &payload.to_json_string().unwrap() );
Using a custom struct:
#[derive(Serialize)] struct CompanyData { foo: &'static str, } let mut payload = SilentNotificationBuilder::new().build("token", Default::default()); let mut custom_data = CompanyData { foo: "bar" }; payload.add_custom_data("foo_data", &custom_data).unwrap(); assert_eq!( "{\"aps\":{\"content-available\":1},\"foo_data\":{\"foo\":\"bar\"}}", &payload.to_json_string().unwrap() );
pub fn to_json_string(self) -> Result<String, Error>
[src]
Combine the APS payload and the custom data to a final payload JSON. Returns an error if serialization fails.
Trait Implementations
Auto Trait Implementations
impl<'a> RefUnwindSafe for Payload<'a>
impl<'a> Send for Payload<'a>
impl<'a> Sync for Payload<'a>
impl<'a> Unpin for Payload<'a>
impl<'a> UnwindSafe for Payload<'a>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,