serialize

Function serialize 

Source
pub fn serialize(job_ref: &dyn Queueable) -> Result<String, Error>
Expand description

Serializes a Queueable trait object into a JSON string.

This function relies on the typetag::serde machinery to serialize the concrete type behind the dyn Queueable. The resulting JSON will include type information so it can be deserialized back into the correct struct.

§Parameters

  • job_ref: A reference to any type that implements the Queueable trait.

§Returns

  • Ok(String) containing the JSON-encoded representation of the job.
  • Err(serde_json::Error) if serialization fails (for instance, due to invalid data).

§Example

use crate::traits::Queueable;
// Suppose `my_job` is some concrete type that implements `Queueable`.
let my_job: &dyn Queueable = &SomeConcreteJob { /* fields */ };

// Serialize the job into a JSON string
match serialize(my_job) {
    Ok(json_str) => println!("Serialized job: {}", json_str),
    Err(e) => eprintln!("Failed to serialize job: {}", e),
}