pub struct MessageBody { /* private fields */ }
Expand description
A message body as described in https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message.
For initialization, it requires a Receiver, which is either a token, a topic or a condition.
After initialization, fields can be set using the setter functions.
§Example
use firebae_cm::{MessageBody, Notification, Receiver};
// Setup of message fields.
let receiver = Receiver::topic("subscribers");
let notification = Notification::new().with_title("Hello, ").with_body("world!");
// Create MessageBody and set the message name and notification.
let mut body = MesageBody::new(receiver);
body.name("Celebration")
.notification(notification);
Implementations§
Source§impl MessageBody
impl MessageBody
Sourcepub fn new(receiver: Receiver) -> Self
pub fn new(receiver: Receiver) -> Self
Creates a new MessageBody using the supplied Receiver. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message.
Sourcepub fn name(&mut self, name: impl Into<String>) -> &mut Self
pub fn name(&mut self, name: impl Into<String>) -> &mut Self
Sets the name of the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message.
Sourcepub fn data(&mut self, data: impl IntoFirebaseMap) -> Result<&mut Self, Error>
pub fn data(&mut self, data: impl IntoFirebaseMap) -> Result<&mut Self, Error>
Sets the data of the message. Accepts any type that implements IntoFirebaseMap, which will construct the required Map<String, String>. For ease, you can use the crate::AsFirebaseMap derive macro on your structs:
use firebae_cm::{AsFirebaseMap, MessageBody, Receiver};
#[derive(AsFirebaseMap)]
struct MessageData {
field1: String,
field2: i32, // Note that this will become a String in Firebase
}
fn main() {
let data = MessageData {
field1: "Hello, world!".to_string(),
field2: 5481,
};
let receiver = Receiver::topic("subscribers");
let mut config = MessageBody::new(receiver);
config.data(data).expect("Data not parsable");
}
See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#resource:-message.
Sourcepub fn notification(&mut self, notification: Notification) -> &mut Self
pub fn notification(&mut self, notification: Notification) -> &mut Self
Sets the notification of the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#notification.
Sourcepub fn android(&mut self, android: AndroidConfig) -> &mut Self
pub fn android(&mut self, android: AndroidConfig) -> &mut Self
Sets the Android configuration for the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#androidconfig.
Sourcepub fn apns(&mut self, apns: ApnsConfig) -> &mut Self
pub fn apns(&mut self, apns: ApnsConfig) -> &mut Self
Sets the Apple configuration for the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#apnsconfig.
Sourcepub fn webpush(&mut self, webpush: WebpushConfig) -> &mut Self
pub fn webpush(&mut self, webpush: WebpushConfig) -> &mut Self
Sets the web configuration for the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#webpushconfig.
Sourcepub fn fcm_options(&mut self, fcm_options: FcmOptions) -> &mut Self
pub fn fcm_options(&mut self, fcm_options: FcmOptions) -> &mut Self
Sets additional Firebase options for the message. See https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages#fcmoptions.
Trait Implementations§
Source§impl Debug for MessageBody
impl Debug for MessageBody
Auto Trait Implementations§
impl Freeze for MessageBody
impl RefUnwindSafe for MessageBody
impl Send for MessageBody
impl Sync for MessageBody
impl Unpin for MessageBody
impl UnwindSafe for MessageBody
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more