Skip to content

Commit f1b7264

Browse files
committed
user: Add documenation to structs and methods
1 parent 18c20d8 commit f1b7264

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/user/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ pub use self::middleware::{Middleware, RequestUser};
2020

2121
pub mod middleware;
2222

23+
/// The model representing a row in the `users` database table.
24+
///
2325
#[derive(Clone, Debug, PartialEq, Eq)]
2426
pub struct User {
2527
pub id: i32,
@@ -31,6 +33,8 @@ pub struct User {
3133
pub api_token: String,
3234
}
3335

36+
/// The serialization format for the `User` model.
37+
///
3438
#[derive(RustcDecodable, RustcEncodable)]
3539
pub struct EncodableUser {
3640
pub id: i32,
@@ -41,6 +45,8 @@ pub struct EncodableUser {
4145
}
4246

4347
impl User {
48+
/// Queries the database for a user with a certain `gh_login` value.
49+
///
4450
pub fn find_by_login(conn: &GenericConnection,
4551
login: &str) -> CargoResult<User> {
4652
let stmt = try!(conn.prepare("SELECT * FROM users
@@ -52,6 +58,8 @@ impl User {
5258
Ok(Model::from_row(&row))
5359
}
5460

61+
/// Queries the database for a user with a certain `api_token` value.
62+
///
5563
pub fn find_by_api_token(conn: &GenericConnection,
5664
token: &str) -> CargoResult<User> {
5765
let stmt = try!(conn.prepare("SELECT * FROM users \
@@ -62,6 +70,8 @@ impl User {
6270
})
6371
}
6472

73+
/// Updates a user or inserts a new user into the database.
74+
///
6575
pub fn find_or_insert(conn: &GenericConnection,
6676
login: &str,
6777
email: Option<&str>,
@@ -102,10 +112,14 @@ impl User {
102112
}))))
103113
}
104114

115+
/// Generates a new crates.io API token.
116+
///
105117
pub fn new_api_token() -> String {
106118
thread_rng().gen_ascii_chars().take(32).collect()
107119
}
108120

121+
/// Converts this `User` model into an `EncodableUser` for JSON serialization.
122+
///
109123
pub fn encodable(self) -> EncodableUser {
110124
let User { id, email, api_token: _, gh_access_token: _,
111125
name, gh_login, avatar } = self;

0 commit comments

Comments
 (0)