use std::cmp::{Ord, Ordering, PartialOrd};
use serde::{Deserialize, Serialize};
use super::external_docs::ExternalDocs;
#[non_exhaustive]
#[derive(Serialize, Deserialize, Default, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct Tag {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub external_docs: Option<ExternalDocs>,
}
impl Ord for Tag {
fn cmp(&self, other: &Self) -> Ordering {
self.name.cmp(&other.name)
}
}
impl PartialOrd for Tag {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl From<String> for Tag {
fn from(name: String) -> Self {
Self::new(name)
}
}
impl From<&String> for Tag {
fn from(name: &String) -> Self {
Self::new(name)
}
}
impl<'a> From<&'a str> for Tag {
fn from(name: &'a str) -> Self {
Self::new(name.to_owned())
}
}
impl Tag {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
..Default::default()
}
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
pub fn description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn external_docs(mut self, external_docs: ExternalDocs) -> Self {
self.external_docs = Some(external_docs);
self
}
}