Struct livesplit_core::timing::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
impl Timer
sourcepub fn new(run: Run) -> Result<Self, CreationError>
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.
Consumes the Timer and creates a Shared Timer that can be shared across multiple threads with multiple owners.
sourcepub fn into_run(self, update_splits: bool) -> Run
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.
sourcepub fn replace_run(&mut self, run: Run, update_splits: bool) -> Result<Run, Run>
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.
sourcepub fn set_run(&mut self, run: Run) -> Result<(), Run>
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.
sourcepub fn mark_as_unmodified(&mut self)
pub fn mark_as_unmodified(&mut self)
Marks the Run as unmodified, so that it is known that all the changes have been saved.
sourcepub const fn current_phase(&self) -> TimerPhase
pub const fn current_phase(&self) -> TimerPhase
Returns the current Timer Phase.
sourcepub fn snapshot(&self) -> Snapshot<'_>
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.
sourcepub const fn current_timing_method(&self) -> TimingMethod
pub const fn current_timing_method(&self) -> TimingMethod
Returns the currently selected Timing Method.
sourcepub fn set_current_timing_method(&mut self, method: TimingMethod)
pub fn set_current_timing_method(&mut self, method: TimingMethod)
Sets the current Timing Method to the Timing Method provided.
sourcepub fn toggle_timing_method(&mut self)
pub fn toggle_timing_method(&mut self)
Toggles between the Real Time
and Game Time
timing methods.
sourcepub fn current_comparison(&self) -> &str
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.
sourcepub fn set_current_comparison<S: PopulateString>(
&mut self,
comparison: S
) -> Result<(), ()>
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.
sourcepub fn current_split(&self) -> Option<&Segment>
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.
sourcepub const fn current_split_index(&self) -> Option<usize>
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.
sourcepub fn start(&mut self)
pub fn start(&mut self)
Starts the Timer if there is no attempt in progress. If that’s not the case, nothing happens.
sourcepub fn split(&mut self)
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.
sourcepub fn split_or_start(&mut self)
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.
sourcepub fn skip_split(&mut self)
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.
sourcepub fn undo_split(&mut self)
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
.
sourcepub fn reset(&mut self, update_splits: bool)
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.
sourcepub fn reset_and_set_attempt_as_pb(&mut self)
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.
sourcepub fn toggle_pause(&mut self)
pub fn toggle_pause(&mut self)
Toggles an active attempt between Paused
and Running
.
sourcepub fn toggle_pause_or_start(&mut self)
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.
sourcepub fn undo_all_pauses(&mut self)
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.
sourcepub fn switch_to_next_comparison(&mut self)
pub fn switch_to_next_comparison(&mut self)
Switches the current comparison to the next comparison in the list.
sourcepub fn switch_to_previous_comparison(&mut self)
pub fn switch_to_previous_comparison(&mut self)
Switches the current comparison to the previous comparison in the list.
sourcepub fn current_attempt_duration(&self) -> TimeSpan
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
.
sourcepub fn get_pause_time(&self) -> Option<TimeSpan>
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.
sourcepub const fn is_game_time_initialized(&self) -> bool
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.
sourcepub fn initialize_game_time(&mut self)
pub fn initialize_game_time(&mut self)
Initializes Game Time for the current attempt. Game Time automatically gets uninitialized for each new attempt.
sourcepub fn deinitialize_game_time(&mut self)
pub fn deinitialize_game_time(&mut self)
Deinitializes Game Time for the current attempt.
sourcepub const fn is_game_time_paused(&self) -> bool
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.
sourcepub fn pause_game_time(&mut self)
pub fn pause_game_time(&mut self)
Pauses the Game Timer such that it doesn’t automatically increment similar to Real Time.
sourcepub fn resume_game_time(&mut self)
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.
sourcepub fn set_game_time(&mut self, game_time: TimeSpan)
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.
sourcepub fn loading_times(&self) -> TimeSpan
pub fn loading_times(&self) -> TimeSpan
Accesses the loading times. Loading times are defined as Game Time - Real Time.
sourcepub fn set_loading_times(&mut self, time: TimeSpan)
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.
sourcepub fn set_custom_variable<N, V>(&mut self, name: N, value: V)where
N: PopulateString,
V: PopulateString,
pub fn set_custom_variable<N, V>(&mut self, name: N, value: V)where
N: PopulateString,
V: PopulateString,
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 TotalPlaytime for Timer
impl TotalPlaytime for Timer
source§fn total_playtime(&self) -> TimeSpan
fn total_playtime(&self) -> TimeSpan
Auto Trait Implementations§
impl !RefUnwindSafe for Timer
impl Send for Timer
impl Sync for Timer
impl Unpin for Timer
impl !UnwindSafe for Timer
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_mut()
into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Pointee for T
impl<T> Pointee for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds.