Skip to main content

modo/job/
payload.rs

1use std::ops::Deref;
2
3/// A typed wrapper around a deserialized job payload.
4///
5/// Use `Payload<T>` as a parameter in job handler functions to receive the
6/// deserialized payload. `T` must implement [`serde::de::DeserializeOwned`].
7///
8/// `Payload<T>` implements [`Deref<Target = T>`], so methods on `T` are
9/// accessible directly without `.0`.
10///
11/// # Example
12///
13/// ```rust,no_run
14/// use modo::job::Payload;
15/// use serde::Deserialize;
16///
17/// #[derive(Deserialize)]
18/// struct WelcomePayload { user_id: String }
19///
20/// async fn handle(payload: Payload<WelcomePayload>) -> modo::Result<()> {
21///     println!("user_id = {}", payload.user_id);
22///     Ok(())
23/// }
24/// ```
25pub struct Payload<T>(pub T);
26
27impl<T> Deref for Payload<T> {
28    type Target = T;
29
30    fn deref(&self) -> &Self::Target {
31        &self.0
32    }
33}