pub fn deserialize(payload: &str) -> Result<Box<dyn Queueable>, Error>Expand description
Attempts to deserialize a JSON string into a boxed Queueable trait object.
This function uses Serde (with typetag::serde) to deserialize the given
payload string into a Box<dyn Queueable>, allowing dynamic dispatch to specific
job implementations at runtime.
§Parameters
payload: A JSON-encoded string representing a serializedQueueable.
§Returns
Ok(Box<dyn Queueable>)if the deserialization is successful.Err(serde_json::Error)if deserialization fails (e.g., invalid JSON format or missing fields).
§Example
ⓘ
use crate::traits::Queueable;
// Assume `serialized_job` is a valid JSON representation of a type implementing `Queueable`.
let serialized_job = r#"{
"type": "MyConcreteJob",
"some_field": "some_value"
}"#;
match deserialize(serialized_job) {
Ok(job) => {
// Now you can call job.handle(), etc.
println!("Job deserialized successfully!");
}
Err(e) => eprintln!("Failed to deserialize job: {}", e),
}