Skip to main content

kellnr_db/
doc_queue_entry.rs

1use std::path::PathBuf;
2
3use kellnr_common::canonical_name::CanonicalName;
4use kellnr_common::original_name::NameError;
5use kellnr_common::version::{Version, VersionError};
6
7#[derive(Eq, PartialEq, Debug)]
8pub struct DocQueueEntry {
9    pub id: i64,
10    /// The crate name in lowercase, with the separators it was published with
11    pub name: String,
12    pub version: Version,
13    pub path: PathBuf,
14}
15
16impl DocQueueEntry {
17    pub fn canonical_name(&self) -> Result<CanonicalName, NameError> {
18        CanonicalName::try_from(self.name.as_str())
19    }
20}
21
22impl TryFrom<kellnr_entity::doc_queue::Model> for DocQueueEntry {
23    type Error = VersionError;
24
25    fn try_from(dqm: kellnr_entity::doc_queue::Model) -> Result<Self, Self::Error> {
26        Ok(Self {
27            id: dqm.id,
28            name: dqm.krate,
29            version: Version::try_from(dqm.version.as_str())?,
30            path: PathBuf::from(dqm.path),
31        })
32    }
33}