pesde/registry/src/package.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2024-07-30 11:37:54 +01:00
use chrono::{DateTime, Utc};
use pesde::manifest::target::{Target, TargetKind};
2024-07-30 11:37:54 +01:00
use serde::Serialize;
use std::collections::BTreeSet;
2024-09-02 15:49:40 +01:00
2024-08-13 19:14:41 +01:00
#[derive(Debug, Serialize, Eq, PartialEq)]
2024-07-30 11:37:54 +01:00
pub struct TargetInfo {
kind: TargetKind,
lib: bool,
bin: bool,
}
impl From<Target> for TargetInfo {
fn from(target: Target) -> Self {
2024-08-14 18:55:58 +01:00
(&target).into()
2024-07-30 11:37:54 +01:00
}
}
2024-08-13 19:14:41 +01:00
impl From<&Target> for TargetInfo {
fn from(target: &Target) -> Self {
TargetInfo {
kind: target.kind(),
lib: target.lib_path().is_some(),
bin: target.bin_path().is_some(),
}
}
}
impl Ord for TargetInfo {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.kind.cmp(&other.kind)
}
}
impl PartialOrd for TargetInfo {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
2024-07-30 11:37:54 +01:00
#[derive(Debug, Serialize)]
pub struct PackageResponse {
pub name: String,
pub version: String,
2024-08-13 19:14:41 +01:00
pub targets: BTreeSet<TargetInfo>,
2024-07-30 11:37:54 +01:00
#[serde(skip_serializing_if = "String::is_empty")]
pub description: String,
pub published_at: DateTime<Utc>,
#[serde(skip_serializing_if = "String::is_empty")]
pub license: String,
2024-08-14 18:55:58 +01:00
#[serde(skip_serializing_if = "Vec::is_empty")]
pub authors: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub repository: Option<String>,
2024-07-30 11:37:54 +01:00
}