serde_nanos

Function serialize

source
pub fn serialize<T, S>(nanos: &T, serializer: S) -> Result<S::Ok, S::Error>
where T: ?Sized + Serialize, S: Serializer,
Expand description

Serde serialize_with function to serialize time values as nanoseconds.

This function can be used with either of the following Serde attributes:

  • #[serde(with = "serde_nanos")]
  • #[serde(serialize_with = "serde_nanos::serialize")]
use std::time::Duration;
use serde::Serialize;

#[derive(Serialize)]
struct Message {
    #[serde(with = "serde_nanos")]
    expires_in: Duration,
}