keep-rs 0.2.0

Rust HTTP client SDK for Keep Memory and Knowledge
Documentation
use serde::{Deserialize, Serialize};

#[non_exhaustive]
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Scope {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub user: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub project: Option<String>,
}

impl Scope {
    pub fn personal(user: impl Into<String>) -> Self {
        Self {
            user: Some(user.into()),
            project: None,
        }
    }

    pub fn force_personal(user: impl Into<String>) -> Self {
        Self {
            user: Some(user.into()),
            project: Some(String::new()),
        }
    }

    pub fn project(user: impl Into<String>, project: impl Into<String>) -> Self {
        Self {
            user: Some(user.into()),
            project: Some(project.into()),
        }
    }

    pub fn is_empty(&self) -> bool {
        self.user.is_none() && self.project.is_none()
    }
}