shmap 0.5.0

A key-value store based on linux shared-memory files (shm) for persisting state across program restarts.
Documentation
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use crate::ShmapError;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Metadata {
    pub key: String,
    pub expiration: Option<DateTime<Utc>>,
    pub encrypted: bool,
}

impl Metadata {
    pub fn new(
        key: &str,
        ttl: Option<std::time::Duration>,
        encrypted: bool,
    ) -> Result<Self, ShmapError> {
        let expiration = match ttl {
            Some(ttl) => Some(
                Utc::now()
                    + chrono::Duration::from_std(ttl)
                        .map_err(|_| ShmapError::DurationOutOfRangeError)?,
            ),
            None => None,
        };

        Ok(Self {
            key: key.to_owned(),
            expiration,
            encrypted,
        })
    }
}