pub struct Timer { /* private fields */ }
Expand description

A Timer provides all the capabilities necessary for doing speedrun attempts.

Examples

use livesplit_core::{Run, Segment, Timer, TimerPhase};

// Create a run object that we can use with at least one segment.
let mut run = Run::new();
run.set_game_name("Super Mario Odyssey");
run.set_category_name("Any%");
run.push_segment(Segment::new("Cap Kingdom"));

// Create the timer from the run.
let mut timer = Timer::new(run).expect("Run with at least one segment provided");

// Start a new attempt.
timer.start();
assert_eq!(timer.current_phase(), TimerPhase::Running);

// Create a split.
timer.split();

// The run should be finished now.
assert_eq!(timer.current_phase(), TimerPhase::Ended);

// Reset the attempt and confirm that we want to store the attempt.
timer.reset(true);

// The attempt is now over.
assert_eq!(timer.current_phase(), TimerPhase::NotRunning);

Implementations§

Creates a new Timer based on a Run object storing all the information about the splits. The Run object needs to have at least one segment, so that the Timer can store the final time. If a Run object with no segments is provided, the Timer creation fails.

Consumes the Timer and creates a Shared Timer that can be shared across multiple threads with multiple owners.

Takes out the Run from the Timer and resets the current attempt if there is one in progress. If the splits are to be updated, all the information of the current attempt is stored in the Run’s history. Otherwise the current attempt’s information is discarded.

Replaces the Run object used by the Timer with the Run object provided. If the Run provided contains no segments, it can’t be used for timing and is returned as the Err case of the Result. Otherwise the Run that was in use by the Timer is being returned. Before the Run is returned, the current attempt is reset and the splits are being updated depending on the update_splits parameter.

Sets the Run object used by the Timer with the Run object provided. If the Run provided contains no segments, it can’t be used for timing and is returned as the Err case of the Result. The Run object in use by the Timer is dropped by this method.

Accesses the Run in use by the Timer.

Marks the Run as unmodified, so that it is known that all the changes have been saved.

Returns the current Timer Phase.

Creates a new snapshot of the timer at the point in time of this call. It represents a frozen state of the timer such that calculations can work with an entirely consistent view of the timer without the current time changing underneath.

Returns the currently selected Timing Method.

Sets the current Timing Method to the Timing Method provided.

Toggles between the Real Time and Game Time timing methods.

Returns the current comparison that is being compared against. This may be a custom comparison or one of the Comparison Generators.

Tries to set the current comparison to the comparison specified. If the comparison doesn’t exist Err is returned.

Accesses the split the attempt is currently on. If there’s no attempt in progress or the run finished, None is returned instead.

Accesses the index of the split the attempt is currently on. If there’s no attempt in progress, None is returned instead. This returns an index that is equal to the amount of segments when the attempt is finished, but has not been reset. So you need to be careful when using this value for indexing.

Starts the Timer if there is no attempt in progress. If that’s not the case, nothing happens.

If an attempt is in progress, stores the current time as the time of the current split. The attempt ends if the last split time is stored.

Starts a new attempt or stores the current time as the time of the current split. The attempt ends if the last split time is stored.

Skips the current split if an attempt is in progress and the current split is not the last split.

Removes the split time from the last split if an attempt is in progress and there is a previous split. The Timer Phase also switches to Running if it previously was Ended.

Resets the current attempt if there is one in progress. If the splits are to be updated, all the information of the current attempt is stored in the Run’s history. Otherwise the current attempt’s information is discarded.

Resets the current attempt if there is one in progress. The splits are updated such that the current attempt’s split times are being stored as the new Personal Best.

Pauses an active attempt that is not paused.

Resumes an attempt that is paused.

Toggles an active attempt between Paused and Running.

Toggles an active attempt between Paused and Running or starts an attempt if there’s none in progress.

Removes all the pause times from the current time. If the current attempt is paused, it also resumes that attempt. Additionally, if the attempt is finished, the final split time is adjusted to not include the pause times as well.

Warning

This behavior is not entirely optimal, as generally only the final split time is modified, while all other split times are left unmodified, which may not be what actually happened during the run.

Switches the current comparison to the next comparison in the list.

Switches the current comparison to the previous comparison in the list.

Returns the total duration of the current attempt. This is not affected by the start offset of the run. So if the start offset is -10s and the start() method was called 2s ago, the current time is -8s but the current attempt duration is 2s. If the timer is then however paused for 5s, the current attempt duration is still 2s. So the current attempt duration only counts the time the Timer Phase has actually been Running.

Returns the total amount of time the current attempt has been paused for. None is returned if there have not been any pauses.

Returns whether Game Time is currently initialized. Game Time automatically gets uninitialized for each new attempt.

Initializes Game Time for the current attempt. Game Time automatically gets uninitialized for each new attempt.

Deinitializes Game Time for the current attempt.

Returns whether the Game Timer is currently paused. If the Game Timer is not paused, it automatically increments similar to Real Time.

Pauses the Game Timer such that it doesn’t automatically increment similar to Real Time.

Resumes the Game Timer such that it automatically increments similar to Real Time, starting from the Game Time it was paused at.

Sets the Game Time to the time specified. This also works if the Game Time is paused, which can be used as a way of updating the Game Timer periodically without it automatically moving forward. This ensures that the Game Timer never shows any time that is not coming from the game.

Accesses the loading times. Loading times are defined as Game Time - Real Time.

Instead of setting the Game Time directly, this method can be used to just specify the amount of time the game has been loading. The Game Time is then automatically determined by Real Time - Loading Times.

Sets the value of a custom variable with the name specified. If the variable does not exist, a temporary variable gets created that will not be stored in the splits file.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Calculates the total playtime.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts self into T using Into<T>. Read more
Causes self to use its Binary implementation when Debug-formatted.
Causes self to use its Display implementation when Debug-formatted.
Causes self to use its LowerExp implementation when Debug-formatted.
Causes self to use its LowerHex implementation when Debug-formatted.
Causes self to use its Octal implementation when Debug-formatted.
Causes self to use its Pointer implementation when Debug-formatted.
Causes self to use its UpperExp implementation when Debug-formatted.
Causes self to use its UpperHex implementation when Debug-formatted.
Formats each item in a sequence. Read more

Returns the argument unchanged.

Query the “status” flags for the self file descriptor.
Create a new SetFdFlags value for use with set_fd_flags. Read more
Set the “status” flags for the self file descriptor. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Pipes by value. This is generally the method you want to use. Read more
Borrows self and passes that borrow into the pipe function. Read more
Mutably borrows self and passes that borrow into the pipe function. Read more
Borrows self, then passes self.borrow() into the pipe function. Read more
Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Borrows self, then passes self.as_ref() into the pipe function.
Mutably borrows self, then passes self.as_mut() into the pipe function.
Borrows self, then passes self.deref() into the pipe function.
Mutably borrows self, then passes self.deref_mut() into the pipe function.
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Immutable access to a value. Read more
Mutable access to a value. Read more
Immutable access to the Borrow<B> of a value. Read more
Mutable access to the BorrowMut<B> of a value. Read more
Immutable access to the AsRef<R> view of a value. Read more
Mutable access to the AsMut<R> view of a value. Read more
Immutable access to the Deref::Target of a value. Read more
Mutable access to the Deref::Target of a value. Read more
Calls .tap() only in debug builds, and is erased in release builds.
Calls .tap_mut() only in debug builds, and is erased in release builds.
Calls .tap_borrow() only in debug builds, and is erased in release builds.
Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Calls .tap_ref() only in debug builds, and is erased in release builds.
Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Calls .tap_deref() only in debug builds, and is erased in release builds.
Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Attempts to convert self into T using TryInto<T>. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more