Struct poke_a_mango::ops::Leader
[−]
[src]
pub struct Leader { pub name: String, pub time: DateTime<FixedOffset>, pub score: u64, }
A leaderboard entry.
Examples
Reading a leaderboard, adding an entry to it, then writing it back.
let tf = temp_dir().join("poke-a-mango-doctest").join("ops-Leader-0"); create_dir_all(&tf).unwrap(); let tf = tf.join("leaderboard.toml"); File::create(&tf).unwrap(); let mut leaders = Leader::read(&tf).unwrap(); assert!(leaders.is_empty()); leaders.push(Leader::now("nabijaczleweli".to_string(), 105)); assert_eq!(Leader::write(leaders, &tf), Ok(()));
This could alternatively be done with Leader::append()
.
Fields
name: String
Name the user entered when prompted.
time: DateTime<FixedOffset>
Time the score was achieved.
score: u64
User's score.
Methods
impl Leader
[src]
pub fn now(name: String, score: u64) -> Leader
[src]
Create a new leaderboard entry with time
set to now.
Examples
let ldr = Leader::now("nabijaczleweli".to_string(), 36); assert_eq!(ldr.name, "nabijaczleweli"); assert_eq!(ldr.score, 36);
pub fn read(p: &Path) -> Result<Vec<Leader>, Error>
[src]
Read leaderboard from the specified file.
If the specified file doesn't exist an empty leaderboard is returned.
Examples
let tf = temp_dir().join("poke-a-mango-doctest").join("ops-Leader-read-0"); create_dir_all(&tf).unwrap(); let tf = tf.join("leaderboard.toml"); File::create(&tf).unwrap(); assert_eq!(Leader::read(&tf), Ok(vec![]));
pub fn write(queued_leaders: Vec<Leader>, p: &Path) -> Result<(), Error>
[src]
Save leaderboard to the specified file.
Examples
let tf = temp_dir().join("poke-a-mango-doctest").join("ops-Leader-write-0"); create_dir_all(&tf).unwrap(); Leader::write(vec![Leader::now("nabijaczleweli".to_string(), 105), Leader::now("skorezore".to_string(), 51)], &tf.join("leaderboard.toml")) .unwrap();
pub fn append(ldr: Leader, p: &Path) -> Result<(), Error>
[src]
Append the specified leader to the leaderboard file at the specified path.
This is equivalent to reading it, appending the leader, properly sorting and writing it back.
Examples
let tf = temp_dir().join("poke-a-mango-doctest").join("ops-Leader-append-0"); create_dir_all(&tf).unwrap(); assert_eq!(Leader::append(Leader::now("nabijaczleweli".to_string(), 105), &tf.join("leaderboard.toml")), Ok(()));
Trait Implementations
impl Debug for Leader
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Clone for Leader
[src]
fn clone(&self) -> Leader
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Hash for Leader
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for Leader
[src]
fn eq(&self, __arg_0: &Leader) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Leader) -> bool
[src]
This method tests for !=
.
impl Eq for Leader
[src]
impl Encodable for Leader
[src]
fn encode<__S: Encoder>(&self, __arg_0: &mut __S) -> Result<(), __S::Error>
[src]
Serialize a value using an Encoder
.
impl Decodable for Leader
[src]
fn decode<__D: Decoder>(__arg_0: &mut __D) -> Result<Leader, __D::Error>
[src]
Deserialize a value using a Decoder
.
impl Ord for Leader
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for Leader
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more