|
|
|
@ -1,5 +1,7 @@ |
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use crate::core::value::{
|
|
|
|
ValueDecode, ValueDecodeError, ValueDecoder, ValueEncode, ValueEncodeError,
|
|
|
|
ValueEncoder,
|
|
|
|
@ -23,6 +25,8 @@ const STATUS_ONLINE: u32 = 3; |
|
|
|
PartialOrd,
|
|
|
|
RustcDecodable,
|
|
|
|
RustcEncodable,
|
|
|
|
Serialize,
|
|
|
|
Deserialize,
|
|
|
|
)]
|
|
|
|
pub enum UserStatus {
|
|
|
|
/// The user if offline.
|
|
|
|
@ -90,7 +94,16 @@ impl ValueDecode for UserStatus { |
|
|
|
|
|
|
|
/// This structure contains the last known information about a fellow user.
|
|
|
|
#[derive(
|
|
|
|
Clone, Debug, Eq, Ord, PartialEq, PartialOrd, RustcDecodable, RustcEncodable,
|
|
|
|
Clone,
|
|
|
|
Debug,
|
|
|
|
Eq,
|
|
|
|
Ord,
|
|
|
|
PartialEq,
|
|
|
|
PartialOrd,
|
|
|
|
RustcDecodable,
|
|
|
|
RustcEncodable,
|
|
|
|
Serialize,
|
|
|
|
Deserialize,
|
|
|
|
)]
|
|
|
|
pub struct User {
|
|
|
|
/// The name of the user.
|
|
|
|
@ -112,3 +125,40 @@ pub struct User { |
|
|
|
/// The user's country code.
|
|
|
|
pub country: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::{User, UserStatus};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn serialize_user_status() {
|
|
|
|
assert_eq!(
|
|
|
|
serde_json::to_string(&UserStatus::Offline).unwrap(),
|
|
|
|
r#""Offline""#
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn serialize_user() {
|
|
|
|
assert_eq!(
|
|
|
|
serde_json::to_string(&User {
|
|
|
|
name: "karandeep".to_string(),
|
|
|
|
status: UserStatus::Online,
|
|
|
|
average_speed: 1,
|
|
|
|
num_downloads: 2,
|
|
|
|
unknown: 3,
|
|
|
|
num_files: 4,
|
|
|
|
num_folders: 5,
|
|
|
|
num_free_slots: 6,
|
|
|
|
country: "IN".to_string(),
|
|
|
|
})
|
|
|
|
.unwrap(),
|
|
|
|
[
|
|
|
|
r#"{"name":"karandeep","status":"Online","average_speed":1,"#,
|
|
|
|
r#""num_downloads":2,"unknown":3,"num_files":4,"num_folders":5,"#,
|
|
|
|
r#""num_free_slots":6,"country":"IN"}"#,
|
|
|
|
]
|
|
|
|
.join("")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|