39 lines
16 KiB
HTML
39 lines
16 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A trait outlining the behavior of a timekeeping type."><title>Instant in libsw_core - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="libsw_core" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../libsw_core/index.html">libsw_<wbr>core</a><span class="version">0.3.1</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Instant</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#provided-implementations" title="Provided implementations">Provided implementations</a></li></ul><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.checked_add" title="checked_add">checked_add</a></li><li><a href="#tymethod.checked_sub" title="checked_sub">checked_sub</a></li><li><a href="#tymethod.now" title="now">now</a></li><li><a href="#tymethod.saturating_duration_since" title="saturating_duration_since">saturating_duration_since</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-Instant-for-Instant" title="Instant">Instant</a></li><li><a href="#impl-Instant-for-SystemTime" title="SystemTime">SystemTime</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate libsw_<wbr>core</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">libsw_core</a></span><h1>Trait <span class="trait">Instant</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/libsw_core/instant.rs.html#32-51">Source</a> </span></div><pre class="rust item-decl"><code>pub trait Instant:
|
||
<a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a>
|
||
+ <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>
|
||
+ <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> {
|
||
// Required methods
|
||
fn <a href="#tymethod.now" class="fn">now</a>() -> Self;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.checked_add" class="fn">checked_add</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.checked_sub" class="fn">checked_sub</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self>;
|
||
<span class="item-spacer"></span> fn <a href="#tymethod.saturating_duration_since" class="fn">saturating_duration_since</a>(&self, earlier: Self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>;
|
||
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A trait outlining the behavior of a timekeeping type.</p>
|
||
<p>This trait allows <code>libsw</code> to be agnostic about timekeeping: any type which
|
||
implements <code>Instant</code> can be used within a
|
||
<a href="struct.Stopwatch.html" title="struct libsw_core::Stopwatch"><code>Stopwatch</code></a>.</p>
|
||
<h2 id="provided-implementations"><a class="doc-anchor" href="#provided-implementations">§</a>Provided implementations</h2>
|
||
<p><code>libsw_core</code> provides <code>Instant</code> implementations for timekeeping types in the
|
||
standard library.</p>
|
||
<div><table><thead><tr><th>Type</th><th>Feature flag</th><th>Notes</th></tr></thead><tbody>
|
||
<tr><td><code>std::time::Instant</code></td><td><code>std</code></td><td></td></tr>
|
||
<tr><td><code>std::time::SystemTime</code></td><td><code>std</code></td><td></td></tr>
|
||
<tr><td><code>tokio::time::Instant</code></td><td><code>tokio</code></td><td></td></tr>
|
||
<tr><td><code>coarsetime::Instant</code></td><td><code>coarsetime</code></td><td></td></tr>
|
||
<tr><td><code>quanta::Instant</code></td><td><code>quanta</code></td><td></td></tr>
|
||
<tr><td><code>time::Instant</code></td><td><code>time</code></td><td>Deprecated.</td></tr>
|
||
</tbody></table>
|
||
</div>
|
||
<p>If a timekeeping type you want to use isn’t supported out of the box, please
|
||
consider <a href="https://gitlab.com/nissaofthesea/libsw-core/-/issues">filing an issue</a>
|
||
on GitLab. If you already implemented <code>Instant</code> for it, consider sending a
|
||
PR upstream.</p>
|
||
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.now" class="method"><a class="src rightside" href="../src/libsw_core/instant.rs.html#34">Source</a><h4 class="code-header">fn <a href="#tymethod.now" class="fn">now</a>() -> Self</h4></section></summary><div class="docblock"><p>Returns the current instant in time.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.checked_add" class="method"><a class="src rightside" href="../src/libsw_core/instant.rs.html#40">Source</a><h4 class="code-header">fn <a href="#tymethod.checked_add" class="fn">checked_add</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section></summary><div class="docblock"><p>Returns an instant ahead of <code>self</code> by the given <a href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration"><code>Duration</code></a> of time.</p>
|
||
<p>Returns <a href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html#variant.None" title="variant core::option::Option::None"><code>None</code></a> if overflow occured, meaning the new instant was not
|
||
representable with the underlying type.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.checked_sub" class="method"><a class="src rightside" href="../src/libsw_core/instant.rs.html#46">Source</a><h4 class="code-header">fn <a href="#tymethod.checked_sub" class="fn">checked_sub</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section></summary><div class="docblock"><p>Returns an instant previous to <code>self</code> by the given <a href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration"><code>Duration</code></a> of time.</p>
|
||
<p>Returns <a href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html#variant.None" title="variant core::option::Option::None"><code>None</code></a> if overflow occured, meaning the new instant was not
|
||
representable with the underlying type.</p>
|
||
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.saturating_duration_since" class="method"><a class="src rightside" href="../src/libsw_core/instant.rs.html#50">Source</a><h4 class="code-header">fn <a href="#tymethod.saturating_duration_since" class="fn">saturating_duration_since</a>(&self, earlier: Self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a></h4></section></summary><div class="docblock"><p>Returns the <a href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration"><code>Duration</code></a> that has elapsed since <code>earlier</code>, returning
|
||
<a href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html#associatedconstant.ZERO" title="associated constant core::time::Duration::ZERO"><code>Duration::ZERO</code></a> if <code>earlier</code> is ahead of <code>self</code>.</p>
|
||
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/1.84.0/reference/items/traits.html#object-safety">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-Instant-for-Instant" class="impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_instant.rs.html#11-27">Source</a><a href="#impl-Instant-for-Instant" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Instant.html" title="trait libsw_core::Instant">Instant</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.0/std/time/struct.Instant.html" title="struct std::time::Instant">Instant</a></h3></section></summary><div class="impl-items"><section id="method.now" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_instant.rs.html#12-14">Source</a><a href="#method.now" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.now" class="fn">now</a>() -> Self</h4></section><section id="method.checked_add" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_instant.rs.html#16-18">Source</a><a href="#method.checked_add" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.checked_add" class="fn">checked_add</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section><section id="method.checked_sub" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_instant.rs.html#20-22">Source</a><a href="#method.checked_sub" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.checked_sub" class="fn">checked_sub</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section><section id="method.saturating_duration_since" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_instant.rs.html#24-26">Source</a><a href="#method.saturating_duration_since" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.saturating_duration_since" class="fn">saturating_duration_since</a>(&self, earlier: Self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a></h4></section></div></details><details class="toggle implementors-toggle"><summary><section id="impl-Instant-for-SystemTime" class="impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_systemtime.rs.html#11-29">Source</a><a href="#impl-Instant-for-SystemTime" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.Instant.html" title="trait libsw_core::Instant">Instant</a> for <a class="struct" href="https://doc.rust-lang.org/1.84.0/std/time/struct.SystemTime.html" title="struct std::time::SystemTime">SystemTime</a></h3></section></summary><div class="impl-items"><section id="method.now-1" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_systemtime.rs.html#12-14">Source</a><a href="#method.now-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.now" class="fn">now</a>() -> Self</h4></section><section id="method.checked_add-1" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_systemtime.rs.html#16-18">Source</a><a href="#method.checked_add-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.checked_add" class="fn">checked_add</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section><section id="method.checked_sub-1" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_systemtime.rs.html#20-22">Source</a><a href="#method.checked_sub-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.checked_sub" class="fn">checked_sub</a>(&self, duration: <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a>) -> <a class="enum" href="https://doc.rust-lang.org/1.84.0/core/option/enum.Option.html" title="enum core::option::Option">Option</a><Self></h4></section><section id="method.saturating_duration_since-1" class="method trait-impl"><a class="src rightside" href="../src/libsw_core/instant_impls/std_systemtime.rs.html#24-28">Source</a><a href="#method.saturating_duration_since-1" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.saturating_duration_since" class="fn">saturating_duration_since</a>(&self, earlier: Self) -> <a class="struct" href="https://doc.rust-lang.org/1.84.0/core/time/struct.Duration.html" title="struct core::time::Duration">Duration</a></h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/libsw_core/instant/trait.Instant.js" data-ignore-extern-crates="std" async></script></section></div></main></body></html> |