46 lines
11 KiB
HTML
46 lines
11 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="`libsw` is a comprehensive stopwatch implementation."><title>libsw - 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" 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="../crates.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 mod crate"><!--[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/index.html">libsw</a><span class="version">3.4.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#introduction" title="Introduction">Introduction</a></li><li><a href="#features" title="Features">Features</a><ul><li><a href="#timekeeping-support" title="Timekeeping support">Timekeeping support</a></li><li><a href="#no_std-support" title="`no_std` support"><code>no_std</code> support</a></li></ul></li><li><a href="#compiler-support" title="Compiler support">Compiler support</a></li><li><a href="#safety" title="Safety">Safety</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"></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"><h1>Crate <span>libsw</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/lib.rs.html#5-140">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p><code>libsw</code> is a comprehensive stopwatch implementation.</p>
|
||
<p>It offers <a href="struct.StopwatchImpl.html#method.checked_stop" title="method libsw::StopwatchImpl::checked_stop">checked stopping</a> and
|
||
<a href="struct.StopwatchImpl.html#method.checked_add" title="method libsw::StopwatchImpl::checked_add">arithmetic</a>, <a href="struct.StopwatchImpl.html#method.start_at" title="method libsw::StopwatchImpl::start_at">precise
|
||
control</a> over when operations occur, and supports
|
||
<a href="trait.Instant.html" title="trait libsw::Instant">arbitrary timekeeping types</a>.</p>
|
||
<p>If you want to do benchmarking, please use something like
|
||
<a href="https://docs.rs/criterion">Criterion</a>.</p>
|
||
<h2 id="introduction"><a class="doc-anchor" href="#introduction">§</a>Introduction</h2>
|
||
<p><code>libsw</code> provides the <a href="struct.StopwatchImpl.html" title="struct libsw::StopwatchImpl"><code>StopwatchImpl</code></a> type as a stopwatch.</p>
|
||
<p>This implementation is agnostic to the timekeeping type used, by virtue of
|
||
being generic. Any type <code>I</code> that implements the <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> trait (as in
|
||
<code>StopwatchImpl<I></code>) can be used for timekeeping.</p>
|
||
<p><code>Instant</code> is implemented for several timekeeping types out of the box (see
|
||
<a href="#timekeeping-support">timekeeping support</a>). If present, these
|
||
implementations are exposed as type aliases.</p>
|
||
<h2 id="features"><a class="doc-anchor" href="#features">§</a>Features</h2><div><table><thead><tr><th>Name</th><th>Features enabled</th><th>Description</th></tr></thead><tbody>
|
||
<tr><td><code>default</code></td><td><code>std_instant</code>, <code>std_systemtime</code></td><td>Enabled by default.</td></tr>
|
||
<tr><td><code>std</code></td><td></td><td>Depends on the standard library. Implements <code>std::error::Error</code> for <a href="enum.Error.html" title="enum libsw::Error"><code>Error</code></a>.</td></tr>
|
||
<tr><td><code>nightly</code></td><td></td><td>Implements <code>core::error::Error</code> for <a href="enum.Error.html" title="enum libsw::Error"><code>Error</code></a> <strong>if</strong> <code>std</code> is not enabled. Requires a nightly compiler.</td></tr>
|
||
<tr><td><code>std_instant</code></td><td><code>std</code></td><td>Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>std::time::Instant</code>. Exposes <code>Sw</code> type alias.</td></tr>
|
||
<tr><td><code>std_systemtime</code></td><td><code>std</code></td><td>Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>std::time::SystemTime</code>. Exposes <code>SystemSw</code> type alias.</td></tr>
|
||
<tr><td><code>tokio</code></td><td><code>std</code></td><td>Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>tokio::time::Instant</code>. Exposes <code>TokioSw</code> type alias.</td></tr>
|
||
<tr><td><code>coarsetime</code></td><td><code>std</code></td><td>Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>coarsetime::Instant</code>. Exposes <code>CoarseSw</code> type alias.</td></tr>
|
||
<tr><td><code>quanta</code></td><td><code>std</code></td><td>Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>quanta::Instant</code>. Exposes <code>QuantaSw</code> type alias.</td></tr>
|
||
<tr><td><code>time</code></td><td><code>std</code></td><td>Deprecated. Implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a> for <code>time::Instant</code>. Exposes <code>TimeSw</code> type alias.</td></tr>
|
||
</tbody></table>
|
||
</div><h3 id="timekeeping-support"><a class="doc-anchor" href="#timekeeping-support">§</a>Timekeeping support</h3>
|
||
<p><code>libsw</code> can be used with any timekeeping type that implements <a href="trait.Instant.html" title="trait libsw::Instant"><code>Instant</code></a>,
|
||
as long as the appropriate feature flag is enabled.</p>
|
||
<p>See <code>Instant</code>’s <a href="trait.Instant.html#provided-implementations" title="trait libsw::Instant">documentation</a> for a list
|
||
of types supported out of the box.</p>
|
||
<h3 id="no_std-support"><a class="doc-anchor" href="#no_std-support">§</a><code>no_std</code> support</h3>
|
||
<p>The <code>std</code> feature flag unsets <code>#[no_std]</code>. It is enabled by default, but you
|
||
can disable it by disabling the default features.</p>
|
||
<p>In <code>Cargo.toml</code>,</p>
|
||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||
# replace '...' with the appropriate version
|
||
libsw = { version = ..., default-features = false }</code></pre></div><h2 id="compiler-support"><a class="doc-anchor" href="#compiler-support">§</a>Compiler support</h2>
|
||
<p>Standalone, the minimum supported version of Rust is <code>1.61.0</code>.
|
||
Adding dependencies may bump this.</p>
|
||
<h2 id="safety"><a class="doc-anchor" href="#safety">§</a>Safety</h2>
|
||
<p><code>libsw</code> contains no unsafe code (<code>#![forbid(unsafe_code)]</code>).</p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Guard.html" title="struct libsw::Guard">Guard</a></div><div class="desc docblock-short">A running, guarded, <a href="struct.StopwatchImpl.html" title="struct libsw::StopwatchImpl">stopwatch</a>. When <a href="struct.Guard.html#method.drop" title="method libsw::Guard::drop">dropped</a>,
|
||
the stopwatch will automatically stop.</div></li><li><div class="item-name"><a class="struct" href="struct.StopwatchImpl.html" title="struct libsw::StopwatchImpl">Stopwatch<wbr>Impl</a></div><div class="desc docblock-short">A stopwatch measures and accumulates elapsed time between starts and stops.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.Error.html" title="enum libsw::Error">Error</a></div><div class="desc docblock-short">Enumeration over possible errors.</div></li></ul><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="trait" href="trait.Instant.html" title="trait libsw::Instant">Instant</a></div><div class="desc docblock-short">A trait outlining the behavior of a timekeeping type.</div></li></ul><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="type" href="type.Result.html" title="type libsw::Result">Result</a></div><div class="desc docblock-short">Alias to <code>Result<T, Error></code>.</div></li><li><div class="item-name"><a class="type" href="type.Stopwatch.html" title="type libsw::Stopwatch">Stopwatch</a><wbr><span class="stab deprecated" title="">Deprecated</span></div><div class="desc docblock-short">Deprecated alias to the “default” stopwatch.</div></li><li><div class="item-name"><a class="type" href="type.Sw.html" title="type libsw::Sw">Sw</a></div><div class="desc docblock-short">Alias to <a href="struct.StopwatchImpl.html" title="struct libsw::StopwatchImpl"><code>StopwatchImpl</code></a> using the standard library’s
|
||
<a href="https://doc.rust-lang.org/1.84.0/std/time/struct.Instant.html" title="struct std::time::Instant"><code>Instant</code></a> type.</div></li><li><div class="item-name"><a class="type" href="type.SystemSw.html" title="type libsw::SystemSw">System<wbr>Sw</a></div><div class="desc docblock-short">Alias to <a href="struct.StopwatchImpl.html" title="struct libsw::StopwatchImpl"><code>StopwatchImpl</code></a> using the standard library’s
|
||
<a href="https://doc.rust-lang.org/1.84.0/std/time/struct.SystemTime.html" title="struct std::time::SystemTime"><code>SystemTime</code></a> type.</div></li></ul></section></div></main></body></html> |