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 the user entered when prompted.

Time the score was achieved.

User's score.

Methods

impl Leader
[src]

[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);

[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![]));

[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();

[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]

[src]

Formats the value using the given formatter. Read more

impl Clone for Leader
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Hash for Leader
[src]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq for Leader
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for Leader
[src]

impl Encodable for Leader
[src]

[src]

Serialize a value using an Encoder.

impl Decodable for Leader
[src]

[src]

Deserialize a value using a Decoder.

impl Ord for Leader
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl PartialOrd for Leader
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more