Skip to content

Commit a7a0dbb

Browse files
committed
git::Crate: Extract separate DependencyKind enum
We will extract the `git` module into a dedicated crate in one of the next commits. This would be impossible if the crate had to depend on the main crate, since it would result in a cyclic dependency.
1 parent 82105a9 commit a7a0dbb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/controllers/krate/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ pub fn add_dependencies(
355355
optional: dep.optional,
356356
default_features: dep.default_features,
357357
target: dep.target.clone(),
358-
kind: dep.kind.or(Some(DependencyKind::Normal)),
358+
kind: dep.kind.or(Some(DependencyKind::Normal)).map(|dk| dk.into()),
359359
package,
360360
},
361361
(

src/git.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ use std::process::Command;
77
use tempfile::TempDir;
88
use url::Url;
99

10-
use crate::models::DependencyKind;
11-
1210
static DEFAULT_GIT_SSH_USERNAME: &str = "git";
1311

1412
#[derive(Clone)]
@@ -148,6 +146,14 @@ pub struct Dependency {
148146
pub package: Option<String>,
149147
}
150148

149+
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
150+
#[serde(rename_all = "lowercase")]
151+
pub enum DependencyKind {
152+
Normal,
153+
Build,
154+
Dev,
155+
}
156+
151157
pub struct RepositoryConfig {
152158
pub index_location: Url,
153159
pub credentials: Credentials,

src/models/dependency.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use diesel::deserialize::{self, FromSql};
22
use diesel::pg::Pg;
33
use diesel::sql_types::Integer;
44

5+
use crate::git::DependencyKind as IndexDependencyKind;
56
use crate::models::{Crate, Version};
67
use crate::schema::*;
78

@@ -42,6 +43,16 @@ pub enum DependencyKind {
4243
// if you add a kind here, be sure to update `from_row` below.
4344
}
4445

46+
impl From<DependencyKind> for IndexDependencyKind {
47+
fn from(dk: DependencyKind) -> Self {
48+
match dk {
49+
DependencyKind::Normal => IndexDependencyKind::Normal,
50+
DependencyKind::Build => IndexDependencyKind::Build,
51+
DependencyKind::Dev => IndexDependencyKind::Dev,
52+
}
53+
}
54+
}
55+
4556
impl FromSql<Integer, Pg> for DependencyKind {
4657
fn from_sql(bytes: Option<&[u8]>) -> deserialize::Result<Self> {
4758
match <i32 as FromSql<Integer, Pg>>::from_sql(bytes)? {

0 commit comments

Comments
 (0)