Skip to content

Commit c1ce4b5

Browse files
authored
views/krate_publish: Remove unnecessary EncodableCategory struct (#7208)
There appears to be no relevant benefit from wrapping the category strings in a newtype struct here, since no custom deserialization/validation is performed.
1 parent 05696a6 commit c1ce4b5

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/tests/builders/publish.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,7 @@ impl PublishBuilder {
151151
.map(u::EncodableKeyword)
152152
.collect(),
153153
),
154-
categories: u::EncodableCategoryList(
155-
self.categories
156-
.clone()
157-
.into_iter()
158-
.map(u::EncodableCategory)
159-
.collect(),
160-
),
154+
categories: u::EncodableCategoryList(self.categories.clone()),
161155
};
162156

163157
let mut tarball_builder = TarballBuilder::new();

src/views/krate_publish.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ pub struct EncodableKeywordList(pub Vec<EncodableKeyword>);
3939
#[derive(Serialize, Debug, Deref)]
4040
pub struct EncodableKeyword(pub String);
4141
#[derive(Serialize, Debug, Deref, Default)]
42-
pub struct EncodableCategoryList(pub Vec<EncodableCategory>);
43-
#[derive(Serialize, Deserialize, Debug, Deref)]
44-
pub struct EncodableCategory(pub String);
42+
pub struct EncodableCategoryList(pub Vec<String>);
4543
#[derive(Serialize, Clone, Debug, Deref)]
4644
pub struct EncodableFeature(pub String);
4745
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Clone, Debug, Deref)]
@@ -185,7 +183,7 @@ impl<'de> Deserialize<'de> for EncodableKeywordList {
185183

186184
impl<'de> Deserialize<'de> for EncodableCategoryList {
187185
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<EncodableCategoryList, D::Error> {
188-
let inner = <Vec<EncodableCategory> as Deserialize<'de>>::deserialize(d)?;
186+
let inner = <Vec<String> as Deserialize<'de>>::deserialize(d)?;
189187
if inner.len() > 5 {
190188
let expected = "at most 5 categories per crate";
191189
Err(de::Error::invalid_length(inner.len(), &expected))

0 commit comments

Comments
 (0)