Skip to content

Commit 85c664b

Browse files
committed
models::user: Inline encodable_public() method
1 parent 09a2899 commit 85c664b

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/models/user.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::util::errors::AppResult;
77

88
use crate::models::{ApiToken, Crate, CrateOwner, Email, NewEmail, Owner, OwnerKind, Rights};
99
use crate::schema::{crate_owners, emails, users};
10-
use crate::views::{EncodablePrivateUser, EncodablePublicUser};
10+
use crate::views::EncodablePrivateUser;
1111

1212
/// The model representing a row in the `users` database table.
1313
#[derive(Clone, Debug, PartialEq, Eq, Queryable, Identifiable, AsChangeset, Associations)]
@@ -203,23 +203,4 @@ impl User {
203203
.first(&*conn)
204204
.optional()?)
205205
}
206-
207-
/// Converts this`User` model into an `EncodablePublicUser` for JSON serialization.
208-
pub fn encodable_public(self) -> EncodablePublicUser {
209-
let User {
210-
id,
211-
name,
212-
gh_login,
213-
gh_avatar,
214-
..
215-
} = self;
216-
let url = format!("https://github.com/{}", gh_login);
217-
EncodablePublicUser {
218-
id,
219-
avatar: gh_avatar,
220-
login: gh_login,
221-
name,
222-
url: Some(url),
223-
}
224-
}
225206
}

src/views.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,24 @@ pub struct EncodablePublicUser {
322322
pub url: Option<String>,
323323
}
324324

325+
/// Converts a `User` model into an `EncodablePublicUser` for JSON serialization.
325326
impl From<User> for EncodablePublicUser {
326327
fn from(user: User) -> Self {
327-
user.encodable_public()
328+
let User {
329+
id,
330+
name,
331+
gh_login,
332+
gh_avatar,
333+
..
334+
} = user;
335+
let url = format!("https://github.com/{}", gh_login);
336+
EncodablePublicUser {
337+
id,
338+
avatar: gh_avatar,
339+
login: gh_login,
340+
name,
341+
url: Some(url),
342+
}
328343
}
329344
}
330345

0 commit comments

Comments
 (0)