Timer

Struct Timer 

Source
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§

Source§

impl Timer

Source

pub fn new(run: Run) -> Result<Self, CreationError>

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.

Source

pub fn into_shared(self) -> SharedTimer

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

Source

pub fn into_run(self, update_splits: bool) -> Run

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.

Source

pub fn replace_run(&mut self, run: Run, update_splits: bool) -> Result<Run, Run>

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.

Source

pub fn set_run(&mut self, run: Run) -> Result<(), Run>

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.

Source

pub const fn run(&self) -> &Run

Accesses the Run in use by the Timer.

Source

pub fn mark_as_unmodified(&mut self)

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

Source

pub const fn current_phase(&self) -> TimerPhase

Returns the current Timer Phase.

Source

pub fn snapshot(&self) -> Snapshot<'_>

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.

Source

pub const fn current_timing_method(&self) -> TimingMethod

Returns the currently selected Timing Method.

Source

pub fn set_current_timing_method(&mut self, method: TimingMethod)

Sets the current Timing Method to the Timing Method provided.

Source

pub fn toggle_timing_method(&mut self)

Toggles between the Real Time and Game Time timing methods.

Source

pub fn current_comparison(&self) -> &str

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

Source

pub fn set_current_comparison<S: PopulateString>( &mut self, comparison: S, ) -> Result<(), ()>

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

Source

pub fn current_split(&self) -> Option<&Segment>

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

Source

pub const fn current_split_index(&self) -> Option<usize>

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.

Source

pub fn start(&mut self)

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

Source

pub fn split(&mut self)

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.

Source

pub fn split_or_start(&mut self)

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.

Source

pub fn skip_split(&mut self)

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

Source

pub fn undo_split(&mut self)

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.

Source

pub fn reset(&mut self, update_splits: bool)

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.

Source

pub fn reset_and_set_attempt_as_pb(&mut self)

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.

Source

pub fn pause(&mut self)

Pauses an active attempt that is not paused.

Source

pub fn resume(&mut self)

Resumes an attempt that is paused.

Source

pub fn toggle_pause(&mut self)

Toggles an active attempt between Paused and Running.

Source

pub fn toggle_pause_or_start(&mut self)

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

Source

pub fn undo_all_pauses(&mut self)

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.

Source

pub fn switch_to_next_comparison(&mut self)

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

Source

pub fn switch_to_previous_comparison(&mut self)

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

Source

pub fn current_attempt_duration(&self) -> TimeSpan

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.

Source

pub fn get_pause_time(&self) -> Option<TimeSpan>

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

Source

pub const fn is_game_time_initialized(&self) -> bool

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

Source

pub fn initialize_game_time(&mut self)

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

Source

pub fn deinitialize_game_time(&mut self)

Deinitializes Game Time for the current attempt.

Source

pub const fn is_game_time_paused(&self) -> bool

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

Source

pub fn pause_game_time(&mut self)

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

Source

pub fn resume_game_time(&mut self)

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

Source

pub fn set_game_time(&mut self, game_time: TimeSpan)

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.

Source

pub fn loading_times(&self) -> TimeSpan

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

Source

pub fn set_loading_times(&mut self, time: TimeSpan)

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.

Source

pub fn set_custom_variable<N, V>(&mut self, name: N, value: V)

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§

Source§

impl Clone for Timer

Source§

fn clone(&self) -> Timer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Timer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl TotalPlaytime for Timer

Source§

fn total_playtime(&self) -> TimeSpan

Calculates the total playtime.

Auto Trait Implementations§

§

impl Freeze for Timer

§

impl !RefUnwindSafe for Timer

§

impl Send for Timer

§

impl Sync for Timer

§

impl Unpin for Timer

§

impl !UnwindSafe for Timer

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> GetSetFdFlags for T

Source§

fn get_fd_flags(&self) -> Result<FdFlags, Error>
where T: AsFilelike,

Query the “status” flags for the self file descriptor.
Source§

fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>
where T: AsFilelike,

Create a new SetFdFlags value for use with set_fd_flags. Read more
Source§

fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>
where T: AsFilelike,

Set the “status” flags for the self file descriptor. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Pointee for T

Source§

type Pointer = u32

Source§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,