#![allow(clippy::module_name_repetitions)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DependencyKind {
Normal,
Dev,
Build,
Peer,
Optional,
}
impl DependencyKind {
#[must_use]
pub const fn is_dev(&self) -> bool {
matches!(self, Self::Dev)
}
#[must_use]
pub const fn is_normal(&self) -> bool {
matches!(self, Self::Normal)
}
#[must_use]
pub const fn is_optional(&self) -> bool {
matches!(self, Self::Optional)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ExternalDependency {
pub name: String,
pub kind: DependencyKind,
pub is_optional: bool,
}
impl ExternalDependency {
#[must_use]
pub fn new(name: impl Into<String>, kind: DependencyKind, is_optional: bool) -> Self {
Self {
name: name.into(),
kind,
is_optional,
}
}
#[must_use]
pub fn normal(name: impl Into<String>) -> Self {
Self::new(name, DependencyKind::Normal, false)
}
#[must_use]
pub fn dev(name: impl Into<String>) -> Self {
Self::new(name, DependencyKind::Dev, false)
}
#[must_use]
pub fn build(name: impl Into<String>) -> Self {
Self::new(name, DependencyKind::Build, false)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WorkspaceDependency {
pub name: String,
pub kind: DependencyKind,
}
impl WorkspaceDependency {
#[must_use]
pub fn new(name: impl Into<String>, kind: DependencyKind) -> Self {
Self {
name: name.into(),
kind,
}
}
#[must_use]
pub fn normal(name: impl Into<String>) -> Self {
Self::new(name, DependencyKind::Normal)
}
#[must_use]
pub fn dev(name: impl Into<String>) -> Self {
Self::new(name, DependencyKind::Dev)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AffectedPackageInfo {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub reasoning: Option<Vec<String>>,
}
impl AffectedPackageInfo {
#[must_use]
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
reasoning: None,
}
}
#[must_use]
pub fn with_reasoning(name: impl Into<String>, reasoning: Vec<String>) -> Self {
Self {
name: name.into(),
reasoning: Some(reasoning),
}
}
}