Skip to content

Commit 7baa13e

Browse files
committed
models::category: Inline encodable() method
1 parent 822583d commit 7baa13e

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/models/category.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use diesel::{self, *};
33

44
use crate::models::Crate;
55
use crate::schema::*;
6-
use crate::views::EncodableCategory;
76

87
#[derive(Clone, Identifiable, Queryable, QueryableByName, Debug)]
98
#[table_name = "categories"]
@@ -57,25 +56,6 @@ impl Category {
5756
categories::table.filter(Self::with_slugs_case_sensitive(slugs))
5857
}
5958

60-
pub fn encodable(self) -> EncodableCategory {
61-
let Category {
62-
crates_cnt,
63-
category,
64-
slug,
65-
description,
66-
created_at,
67-
..
68-
} = self;
69-
EncodableCategory {
70-
id: slug.clone(),
71-
slug,
72-
description,
73-
created_at,
74-
crates_cnt,
75-
category: category.rsplit("::").collect::<Vec<_>>()[0].to_string(),
76-
}
77-
}
78-
7959
pub fn update_crate(
8060
conn: &PgConnection,
8161
krate: &Crate,

src/views.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,22 @@ pub struct EncodableCategory {
3030

3131
impl From<Category> for EncodableCategory {
3232
fn from(category: Category) -> Self {
33-
category.encodable()
33+
let Category {
34+
crates_cnt,
35+
category,
36+
slug,
37+
description,
38+
created_at,
39+
..
40+
} = category;
41+
Self {
42+
id: slug.clone(),
43+
slug,
44+
description,
45+
created_at,
46+
crates_cnt,
47+
category: category.rsplit("::").collect::<Vec<_>>()[0].to_string(),
48+
}
3449
}
3550
}
3651

0 commit comments

Comments
 (0)