Skip to main content

AuthRuntime

Struct AuthRuntime 

Source
pub struct AuthRuntime { /* private fields */ }
Expand description

A handle on a running authentication state. Clones share one handle, so cloning is cheap, and the actor stops once the last clone is dropped.

Implementations§

Source§

impl AuthRuntime

Source

pub async fn from_process(config: AuthConfig) -> Result<Self, AuthFailure>

Source

pub async fn from_isolated_state( config: AuthConfig, ) -> Result<Self, AuthFailure>

Start an embedded relay with an administrator key owned only by its state directory.

This deliberately leaves the process credential untouched because the containing UI uses that credential for its outbound register, connect, status, and stream connections.

Source

pub async fn start( admin_key: AesKeyType, config: AuthConfig, ) -> Result<Self, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 75)
74async fn start(state_dir: &Path, capacity: usize) -> BenchResult<(AuthRuntime, AuthContext)> {
75    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config(state_dir, capacity)).await?;
76    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
77    Ok((runtime, admin))
78}
79
80/// The per-connection checks, which take no lock the actor holds for long.
81async fn hot_path() -> BenchResult<()> {
82    let state_dir = TempPath::new("auth-bench");
83    let (runtime, admin) = start(&state_dir, 16).await?;
84    let issued = runtime.issue(&admin, HOUR, None).await?;
85    let key_id: KeyId = issued.metadata.key_id;
86    let presented = runtime.derive_key(key_id)?;
87
88    let derive = time(|| {
89        black_box(runtime.derive_key(black_box(key_id))?);
90        Ok(())
91    })?;
92    let temporary = time(|| {
93        black_box(runtime.authenticate_presented(black_box(key_id), black_box(&presented))?);
94        Ok(())
95    })?;
96    let administrator =
97        time(|| {
98            black_box(runtime.authenticate_presented(
99                black_box(ADMIN_KEY_ID),
100                black_box(&TEST_ADMIN_KEY_BYTES),
101            )?);
102            Ok(())
103        })?;
104    println!("case=derive_temporary_key ns={derive:.1}");
105    println!("case=authenticate_temporary ns={temporary:.1}");
106    println!("case=authenticate_administrator ns={administrator:.1}");
107
108    drop(admin);
109    runtime.shutdown_actor().await;
110    Ok(())
111}
112
113/// Busy tasks that record the longest wait between two of their turns.
114struct Probes {
115    /// Nanoseconds, since the last reset.
116    longest_gap: Arc<AtomicU64>,
117    turns: Vec<Arc<AtomicU64>>,
118    stop: Arc<AtomicBool>,
119    tasks: Vec<JoinHandle<()>>,
120}
121
122impl Probes {
123    fn start(count: usize) -> Self {
124        let longest_gap = Arc::new(AtomicU64::new(0));
125        let stop = Arc::new(AtomicBool::new(false));
126        let turns = (0..count)
127            .map(|_| Arc::new(AtomicU64::new(0)))
128            .collect::<Vec<_>>();
129        let tasks = turns
130            .iter()
131            .map(|turns| {
132                let (longest_gap, turns, stop) = (longest_gap.clone(), turns.clone(), stop.clone());
133                tokio::spawn(async move {
134                    let mut last = Instant::now();
135                    while !stop.load(Ordering::Relaxed) {
136                        tokio::task::yield_now().await;
137                        let now = Instant::now();
138                        let gap = u64::try_from((now - last).as_nanos()).unwrap_or(u64::MAX);
139                        longest_gap.fetch_max(gap, Ordering::Relaxed);
140                        turns.fetch_add(1, Ordering::Relaxed);
141                        last = now;
142                    }
143                })
144            })
145            .collect();
146        Self {
147            longest_gap,
148            turns,
149            stop,
150            tasks,
151        }
152    }
153
154    fn turns(&self) -> Vec<u64> {
155        self.turns
156            .iter()
157            .map(|turns| turns.load(Ordering::Relaxed))
158            .collect()
159    }
160
161    /// Waits until every probe has taken two more turns, which closes any gap
162    /// open now.
163    async fn settle(&self) {
164        let before = self.turns();
165        while self
166            .turns()
167            .iter()
168            .zip(&before)
169            .any(|(now, then)| *now < then + 2)
170        {
171            tokio::task::yield_now().await;
172        }
173    }
174
175    /// Runs `operation`, returning its output, how long it took, and the
176    /// longest a probe waited meanwhile.
177    async fn measure<T>(&self, operation: impl Future<Output = T>) -> (T, Timing) {
178        self.settle().await;
179        self.longest_gap.store(0, Ordering::Relaxed);
180        let start = Instant::now();
181        let output = operation.await;
182        let latency = start.elapsed();
183        self.settle().await;
184        let hold = Duration::from_nanos(self.longest_gap.load(Ordering::Relaxed));
185        (output, Timing { latency, hold })
186    }
187
188    async fn stop(self) {
189        self.stop.store(true, Ordering::Relaxed);
190        for task in self.tasks {
191            let _ = task.await;
192        }
193    }
194}
195
196struct Timing {
197    latency: Duration,
198    hold: Duration,
199}
200
201#[derive(Default)]
202struct Timings {
203    latency: Vec<Duration>,
204    hold: Vec<Duration>,
205}
206
207impl Timings {
208    fn push(&mut self, Timing { latency, hold }: Timing) {
209        self.latency.push(latency);
210        self.hold.push(hold);
211    }
212
213    fn report(mut self, case: &str) {
214        let micros = |samples: &mut Vec<Duration>, quantile: f64| {
215            samples.sort();
216            let index = ((samples.len() - 1) as f64 * quantile).round() as usize;
217            samples[index].as_secs_f64() * 1e6
218        };
219        println!(
220            "case={case} ops={} latency_p50_us={:.1} latency_p99_us={:.1} hold_p50_us={:.1} hold_p99_us={:.1} hold_max_us={:.1}",
221            self.latency.len(),
222            micros(&mut self.latency, 0.5),
223            micros(&mut self.latency, 0.99),
224            micros(&mut self.hold, 0.5),
225            micros(&mut self.hold, 0.99),
226            micros(&mut self.hold, 1.0),
227        );
228    }
229}
230
231/// The administrator's operations, measured on the runtime this runs on.
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
More examples
Hide additional examples
examples/snapshot_bench.rs (line 86)
73async fn main() -> BenchResult<()> {
74    let seconds = std::env::args()
75        .nth(1)
76        .map(|seconds| seconds.parse::<u64>())
77        .transpose()?
78        .unwrap_or(3600);
79    let state_dir = TempPath::new("snapshot-bench");
80    let config = AuthConfig {
81        state_dir: state_dir.to_path_buf(),
82        max_temporary_keys: DEFAULT_TEMP_KEY_CAPACITY,
83        max_temporary_key_ttl: DEFAULT_MAX_TEMP_KEY_TTL,
84        legacy_protocol: LegacyProtocolPolicy::Deny,
85    };
86    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config).await?;
87    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
88    for _ in 0..KEYS {
89        runtime
90            .issue(&admin, DEFAULT_MAX_TEMP_KEY_TTL, None)
91            .await?;
92    }
93
94    let snapshot = state_dir.join("auth.snapshot");
95    let version = || -> Option<(SystemTime, u64)> {
96        let metadata = std::fs::metadata(&snapshot).ok()?;
97        Some((metadata.modified().ok()?, metadata.len()))
98    };
99    let mut counts = Counts {
100        rewrites: 0,
101        snapshot_bytes: 0,
102        written_at_start: written(),
103    };
104    let mut seen = version();
105    let start = Instant::now();
106    // For telling the idle hours apart in a trace of the run.
107    let since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
108    println!("# idle from unix_ms={}", since_epoch.as_millis());
109    let end = start + Duration::from_secs(seconds);
110    let mut next_report = start + REPORT_EVERY;
111    let mut second = tokio::time::interval(Duration::from_secs(1));
112    while Instant::now() < end {
113        second.tick().await;
114        let now = version();
115        if now != seen {
116            counts.rewrites += 1;
117            counts.snapshot_bytes += now.map_or(0, |(_, len)| len);
118            seen = now;
119        }
120        if Instant::now() >= next_report {
121            counts.report(start.elapsed());
122            next_report += REPORT_EVERY;
123        }
124    }
125    counts.report(start.elapsed());
126
127    drop(admin);
128    runtime.shutdown_actor().await;
129    Ok(())
130}
Source

pub async fn shutdown_actor(&self)

Examples found in repository?
examples/auth_bench.rs (line 109)
81async fn hot_path() -> BenchResult<()> {
82    let state_dir = TempPath::new("auth-bench");
83    let (runtime, admin) = start(&state_dir, 16).await?;
84    let issued = runtime.issue(&admin, HOUR, None).await?;
85    let key_id: KeyId = issued.metadata.key_id;
86    let presented = runtime.derive_key(key_id)?;
87
88    let derive = time(|| {
89        black_box(runtime.derive_key(black_box(key_id))?);
90        Ok(())
91    })?;
92    let temporary = time(|| {
93        black_box(runtime.authenticate_presented(black_box(key_id), black_box(&presented))?);
94        Ok(())
95    })?;
96    let administrator =
97        time(|| {
98            black_box(runtime.authenticate_presented(
99                black_box(ADMIN_KEY_ID),
100                black_box(&TEST_ADMIN_KEY_BYTES),
101            )?);
102            Ok(())
103        })?;
104    println!("case=derive_temporary_key ns={derive:.1}");
105    println!("case=authenticate_temporary ns={temporary:.1}");
106    println!("case=authenticate_administrator ns={administrator:.1}");
107
108    drop(admin);
109    runtime.shutdown_actor().await;
110    Ok(())
111}
112
113/// Busy tasks that record the longest wait between two of their turns.
114struct Probes {
115    /// Nanoseconds, since the last reset.
116    longest_gap: Arc<AtomicU64>,
117    turns: Vec<Arc<AtomicU64>>,
118    stop: Arc<AtomicBool>,
119    tasks: Vec<JoinHandle<()>>,
120}
121
122impl Probes {
123    fn start(count: usize) -> Self {
124        let longest_gap = Arc::new(AtomicU64::new(0));
125        let stop = Arc::new(AtomicBool::new(false));
126        let turns = (0..count)
127            .map(|_| Arc::new(AtomicU64::new(0)))
128            .collect::<Vec<_>>();
129        let tasks = turns
130            .iter()
131            .map(|turns| {
132                let (longest_gap, turns, stop) = (longest_gap.clone(), turns.clone(), stop.clone());
133                tokio::spawn(async move {
134                    let mut last = Instant::now();
135                    while !stop.load(Ordering::Relaxed) {
136                        tokio::task::yield_now().await;
137                        let now = Instant::now();
138                        let gap = u64::try_from((now - last).as_nanos()).unwrap_or(u64::MAX);
139                        longest_gap.fetch_max(gap, Ordering::Relaxed);
140                        turns.fetch_add(1, Ordering::Relaxed);
141                        last = now;
142                    }
143                })
144            })
145            .collect();
146        Self {
147            longest_gap,
148            turns,
149            stop,
150            tasks,
151        }
152    }
153
154    fn turns(&self) -> Vec<u64> {
155        self.turns
156            .iter()
157            .map(|turns| turns.load(Ordering::Relaxed))
158            .collect()
159    }
160
161    /// Waits until every probe has taken two more turns, which closes any gap
162    /// open now.
163    async fn settle(&self) {
164        let before = self.turns();
165        while self
166            .turns()
167            .iter()
168            .zip(&before)
169            .any(|(now, then)| *now < then + 2)
170        {
171            tokio::task::yield_now().await;
172        }
173    }
174
175    /// Runs `operation`, returning its output, how long it took, and the
176    /// longest a probe waited meanwhile.
177    async fn measure<T>(&self, operation: impl Future<Output = T>) -> (T, Timing) {
178        self.settle().await;
179        self.longest_gap.store(0, Ordering::Relaxed);
180        let start = Instant::now();
181        let output = operation.await;
182        let latency = start.elapsed();
183        self.settle().await;
184        let hold = Duration::from_nanos(self.longest_gap.load(Ordering::Relaxed));
185        (output, Timing { latency, hold })
186    }
187
188    async fn stop(self) {
189        self.stop.store(true, Ordering::Relaxed);
190        for task in self.tasks {
191            let _ = task.await;
192        }
193    }
194}
195
196struct Timing {
197    latency: Duration,
198    hold: Duration,
199}
200
201#[derive(Default)]
202struct Timings {
203    latency: Vec<Duration>,
204    hold: Vec<Duration>,
205}
206
207impl Timings {
208    fn push(&mut self, Timing { latency, hold }: Timing) {
209        self.latency.push(latency);
210        self.hold.push(hold);
211    }
212
213    fn report(mut self, case: &str) {
214        let micros = |samples: &mut Vec<Duration>, quantile: f64| {
215            samples.sort();
216            let index = ((samples.len() - 1) as f64 * quantile).round() as usize;
217            samples[index].as_secs_f64() * 1e6
218        };
219        println!(
220            "case={case} ops={} latency_p50_us={:.1} latency_p99_us={:.1} hold_p50_us={:.1} hold_p99_us={:.1} hold_max_us={:.1}",
221            self.latency.len(),
222            micros(&mut self.latency, 0.5),
223            micros(&mut self.latency, 0.99),
224            micros(&mut self.hold, 0.5),
225            micros(&mut self.hold, 0.99),
226            micros(&mut self.hold, 1.0),
227        );
228    }
229}
230
231/// The administrator's operations, measured on the runtime this runs on.
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
More examples
Hide additional examples
examples/snapshot_bench.rs (line 128)
73async fn main() -> BenchResult<()> {
74    let seconds = std::env::args()
75        .nth(1)
76        .map(|seconds| seconds.parse::<u64>())
77        .transpose()?
78        .unwrap_or(3600);
79    let state_dir = TempPath::new("snapshot-bench");
80    let config = AuthConfig {
81        state_dir: state_dir.to_path_buf(),
82        max_temporary_keys: DEFAULT_TEMP_KEY_CAPACITY,
83        max_temporary_key_ttl: DEFAULT_MAX_TEMP_KEY_TTL,
84        legacy_protocol: LegacyProtocolPolicy::Deny,
85    };
86    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config).await?;
87    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
88    for _ in 0..KEYS {
89        runtime
90            .issue(&admin, DEFAULT_MAX_TEMP_KEY_TTL, None)
91            .await?;
92    }
93
94    let snapshot = state_dir.join("auth.snapshot");
95    let version = || -> Option<(SystemTime, u64)> {
96        let metadata = std::fs::metadata(&snapshot).ok()?;
97        Some((metadata.modified().ok()?, metadata.len()))
98    };
99    let mut counts = Counts {
100        rewrites: 0,
101        snapshot_bytes: 0,
102        written_at_start: written(),
103    };
104    let mut seen = version();
105    let start = Instant::now();
106    // For telling the idle hours apart in a trace of the run.
107    let since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
108    println!("# idle from unix_ms={}", since_epoch.as_millis());
109    let end = start + Duration::from_secs(seconds);
110    let mut next_report = start + REPORT_EVERY;
111    let mut second = tokio::time::interval(Duration::from_secs(1));
112    while Instant::now() < end {
113        second.tick().await;
114        let now = version();
115        if now != seen {
116            counts.rewrites += 1;
117            counts.snapshot_bytes += now.map_or(0, |(_, len)| len);
118            seen = now;
119        }
120        if Instant::now() >= next_report {
121            counts.report(start.elapsed());
122            next_report += REPORT_EVERY;
123        }
124    }
125    counts.report(start.elapsed());
126
127    drop(admin);
128    runtime.shutdown_actor().await;
129    Ok(())
130}
Source

pub async fn abort_actor(&self) -> Result<(), AuthFailure>

Source

pub fn config(&self) -> &AuthConfig

Source

pub fn admin_key(&self) -> Result<AesKeyType, AuthFailure>

Source

pub fn derive_key(&self, key_id: KeyId) -> Result<AesKeyType, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 86)
81async fn hot_path() -> BenchResult<()> {
82    let state_dir = TempPath::new("auth-bench");
83    let (runtime, admin) = start(&state_dir, 16).await?;
84    let issued = runtime.issue(&admin, HOUR, None).await?;
85    let key_id: KeyId = issued.metadata.key_id;
86    let presented = runtime.derive_key(key_id)?;
87
88    let derive = time(|| {
89        black_box(runtime.derive_key(black_box(key_id))?);
90        Ok(())
91    })?;
92    let temporary = time(|| {
93        black_box(runtime.authenticate_presented(black_box(key_id), black_box(&presented))?);
94        Ok(())
95    })?;
96    let administrator =
97        time(|| {
98            black_box(runtime.authenticate_presented(
99                black_box(ADMIN_KEY_ID),
100                black_box(&TEST_ADMIN_KEY_BYTES),
101            )?);
102            Ok(())
103        })?;
104    println!("case=derive_temporary_key ns={derive:.1}");
105    println!("case=authenticate_temporary ns={temporary:.1}");
106    println!("case=authenticate_administrator ns={administrator:.1}");
107
108    drop(admin);
109    runtime.shutdown_actor().await;
110    Ok(())
111}
Source

pub fn derive_previous_key(&self, key_id: KeyId) -> Option<AesKeyType>

Source

pub fn authenticate_presented( &self, key_id: KeyId, presented_key: &AesKeyType, ) -> Result<AuthContext, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 76)
74async fn start(state_dir: &Path, capacity: usize) -> BenchResult<(AuthRuntime, AuthContext)> {
75    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config(state_dir, capacity)).await?;
76    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
77    Ok((runtime, admin))
78}
79
80/// The per-connection checks, which take no lock the actor holds for long.
81async fn hot_path() -> BenchResult<()> {
82    let state_dir = TempPath::new("auth-bench");
83    let (runtime, admin) = start(&state_dir, 16).await?;
84    let issued = runtime.issue(&admin, HOUR, None).await?;
85    let key_id: KeyId = issued.metadata.key_id;
86    let presented = runtime.derive_key(key_id)?;
87
88    let derive = time(|| {
89        black_box(runtime.derive_key(black_box(key_id))?);
90        Ok(())
91    })?;
92    let temporary = time(|| {
93        black_box(runtime.authenticate_presented(black_box(key_id), black_box(&presented))?);
94        Ok(())
95    })?;
96    let administrator =
97        time(|| {
98            black_box(runtime.authenticate_presented(
99                black_box(ADMIN_KEY_ID),
100                black_box(&TEST_ADMIN_KEY_BYTES),
101            )?);
102            Ok(())
103        })?;
104    println!("case=derive_temporary_key ns={derive:.1}");
105    println!("case=authenticate_temporary ns={temporary:.1}");
106    println!("case=authenticate_administrator ns={administrator:.1}");
107
108    drop(admin);
109    runtime.shutdown_actor().await;
110    Ok(())
111}
More examples
Hide additional examples
examples/snapshot_bench.rs (line 87)
73async fn main() -> BenchResult<()> {
74    let seconds = std::env::args()
75        .nth(1)
76        .map(|seconds| seconds.parse::<u64>())
77        .transpose()?
78        .unwrap_or(3600);
79    let state_dir = TempPath::new("snapshot-bench");
80    let config = AuthConfig {
81        state_dir: state_dir.to_path_buf(),
82        max_temporary_keys: DEFAULT_TEMP_KEY_CAPACITY,
83        max_temporary_key_ttl: DEFAULT_MAX_TEMP_KEY_TTL,
84        legacy_protocol: LegacyProtocolPolicy::Deny,
85    };
86    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config).await?;
87    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
88    for _ in 0..KEYS {
89        runtime
90            .issue(&admin, DEFAULT_MAX_TEMP_KEY_TTL, None)
91            .await?;
92    }
93
94    let snapshot = state_dir.join("auth.snapshot");
95    let version = || -> Option<(SystemTime, u64)> {
96        let metadata = std::fs::metadata(&snapshot).ok()?;
97        Some((metadata.modified().ok()?, metadata.len()))
98    };
99    let mut counts = Counts {
100        rewrites: 0,
101        snapshot_bytes: 0,
102        written_at_start: written(),
103    };
104    let mut seen = version();
105    let start = Instant::now();
106    // For telling the idle hours apart in a trace of the run.
107    let since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
108    println!("# idle from unix_ms={}", since_epoch.as_millis());
109    let end = start + Duration::from_secs(seconds);
110    let mut next_report = start + REPORT_EVERY;
111    let mut second = tokio::time::interval(Duration::from_secs(1));
112    while Instant::now() < end {
113        second.tick().await;
114        let now = version();
115        if now != seen {
116            counts.rewrites += 1;
117            counts.snapshot_bytes += now.map_or(0, |(_, len)| len);
118            seen = now;
119        }
120        if Instant::now() >= next_report {
121            counts.report(start.elapsed());
122            next_report += REPORT_EVERY;
123        }
124    }
125    counts.report(start.elapsed());
126
127    drop(admin);
128    runtime.shutdown_actor().await;
129    Ok(())
130}
Source

pub fn legacy_protocol_allowed(&self) -> Result<bool, AuthFailure>

Source

pub fn record_legacy_connection( &self, ) -> Result<LegacyConnectionGuard, AuthFailure>

Source

pub async fn claim_admin_mutation( &self, authorization: &AuthContext, fingerprint: [u8; 32], client_timestamp: u64, ) -> Result<(), AuthFailure>

Source

pub async fn issue( &self, authorization: &AuthContext, ttl: Duration, label: Option<String>, ) -> Result<IssuedTemporaryKey, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 84)
81async fn hot_path() -> BenchResult<()> {
82    let state_dir = TempPath::new("auth-bench");
83    let (runtime, admin) = start(&state_dir, 16).await?;
84    let issued = runtime.issue(&admin, HOUR, None).await?;
85    let key_id: KeyId = issued.metadata.key_id;
86    let presented = runtime.derive_key(key_id)?;
87
88    let derive = time(|| {
89        black_box(runtime.derive_key(black_box(key_id))?);
90        Ok(())
91    })?;
92    let temporary = time(|| {
93        black_box(runtime.authenticate_presented(black_box(key_id), black_box(&presented))?);
94        Ok(())
95    })?;
96    let administrator =
97        time(|| {
98            black_box(runtime.authenticate_presented(
99                black_box(ADMIN_KEY_ID),
100                black_box(&TEST_ADMIN_KEY_BYTES),
101            )?);
102            Ok(())
103        })?;
104    println!("case=derive_temporary_key ns={derive:.1}");
105    println!("case=authenticate_temporary ns={temporary:.1}");
106    println!("case=authenticate_administrator ns={administrator:.1}");
107
108    drop(admin);
109    runtime.shutdown_actor().await;
110    Ok(())
111}
112
113/// Busy tasks that record the longest wait between two of their turns.
114struct Probes {
115    /// Nanoseconds, since the last reset.
116    longest_gap: Arc<AtomicU64>,
117    turns: Vec<Arc<AtomicU64>>,
118    stop: Arc<AtomicBool>,
119    tasks: Vec<JoinHandle<()>>,
120}
121
122impl Probes {
123    fn start(count: usize) -> Self {
124        let longest_gap = Arc::new(AtomicU64::new(0));
125        let stop = Arc::new(AtomicBool::new(false));
126        let turns = (0..count)
127            .map(|_| Arc::new(AtomicU64::new(0)))
128            .collect::<Vec<_>>();
129        let tasks = turns
130            .iter()
131            .map(|turns| {
132                let (longest_gap, turns, stop) = (longest_gap.clone(), turns.clone(), stop.clone());
133                tokio::spawn(async move {
134                    let mut last = Instant::now();
135                    while !stop.load(Ordering::Relaxed) {
136                        tokio::task::yield_now().await;
137                        let now = Instant::now();
138                        let gap = u64::try_from((now - last).as_nanos()).unwrap_or(u64::MAX);
139                        longest_gap.fetch_max(gap, Ordering::Relaxed);
140                        turns.fetch_add(1, Ordering::Relaxed);
141                        last = now;
142                    }
143                })
144            })
145            .collect();
146        Self {
147            longest_gap,
148            turns,
149            stop,
150            tasks,
151        }
152    }
153
154    fn turns(&self) -> Vec<u64> {
155        self.turns
156            .iter()
157            .map(|turns| turns.load(Ordering::Relaxed))
158            .collect()
159    }
160
161    /// Waits until every probe has taken two more turns, which closes any gap
162    /// open now.
163    async fn settle(&self) {
164        let before = self.turns();
165        while self
166            .turns()
167            .iter()
168            .zip(&before)
169            .any(|(now, then)| *now < then + 2)
170        {
171            tokio::task::yield_now().await;
172        }
173    }
174
175    /// Runs `operation`, returning its output, how long it took, and the
176    /// longest a probe waited meanwhile.
177    async fn measure<T>(&self, operation: impl Future<Output = T>) -> (T, Timing) {
178        self.settle().await;
179        self.longest_gap.store(0, Ordering::Relaxed);
180        let start = Instant::now();
181        let output = operation.await;
182        let latency = start.elapsed();
183        self.settle().await;
184        let hold = Duration::from_nanos(self.longest_gap.load(Ordering::Relaxed));
185        (output, Timing { latency, hold })
186    }
187
188    async fn stop(self) {
189        self.stop.store(true, Ordering::Relaxed);
190        for task in self.tasks {
191            let _ = task.await;
192        }
193    }
194}
195
196struct Timing {
197    latency: Duration,
198    hold: Duration,
199}
200
201#[derive(Default)]
202struct Timings {
203    latency: Vec<Duration>,
204    hold: Vec<Duration>,
205}
206
207impl Timings {
208    fn push(&mut self, Timing { latency, hold }: Timing) {
209        self.latency.push(latency);
210        self.hold.push(hold);
211    }
212
213    fn report(mut self, case: &str) {
214        let micros = |samples: &mut Vec<Duration>, quantile: f64| {
215            samples.sort();
216            let index = ((samples.len() - 1) as f64 * quantile).round() as usize;
217            samples[index].as_secs_f64() * 1e6
218        };
219        println!(
220            "case={case} ops={} latency_p50_us={:.1} latency_p99_us={:.1} hold_p50_us={:.1} hold_p99_us={:.1} hold_max_us={:.1}",
221            self.latency.len(),
222            micros(&mut self.latency, 0.5),
223            micros(&mut self.latency, 0.99),
224            micros(&mut self.hold, 0.5),
225            micros(&mut self.hold, 0.99),
226            micros(&mut self.hold, 1.0),
227        );
228    }
229}
230
231/// The administrator's operations, measured on the runtime this runs on.
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
More examples
Hide additional examples
examples/snapshot_bench.rs (line 90)
73async fn main() -> BenchResult<()> {
74    let seconds = std::env::args()
75        .nth(1)
76        .map(|seconds| seconds.parse::<u64>())
77        .transpose()?
78        .unwrap_or(3600);
79    let state_dir = TempPath::new("snapshot-bench");
80    let config = AuthConfig {
81        state_dir: state_dir.to_path_buf(),
82        max_temporary_keys: DEFAULT_TEMP_KEY_CAPACITY,
83        max_temporary_key_ttl: DEFAULT_MAX_TEMP_KEY_TTL,
84        legacy_protocol: LegacyProtocolPolicy::Deny,
85    };
86    let runtime = AuthRuntime::start(TEST_ADMIN_KEY_BYTES, config).await?;
87    let admin = runtime.authenticate_presented(ADMIN_KEY_ID, &TEST_ADMIN_KEY_BYTES)?;
88    for _ in 0..KEYS {
89        runtime
90            .issue(&admin, DEFAULT_MAX_TEMP_KEY_TTL, None)
91            .await?;
92    }
93
94    let snapshot = state_dir.join("auth.snapshot");
95    let version = || -> Option<(SystemTime, u64)> {
96        let metadata = std::fs::metadata(&snapshot).ok()?;
97        Some((metadata.modified().ok()?, metadata.len()))
98    };
99    let mut counts = Counts {
100        rewrites: 0,
101        snapshot_bytes: 0,
102        written_at_start: written(),
103    };
104    let mut seen = version();
105    let start = Instant::now();
106    // For telling the idle hours apart in a trace of the run.
107    let since_epoch = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH)?;
108    println!("# idle from unix_ms={}", since_epoch.as_millis());
109    let end = start + Duration::from_secs(seconds);
110    let mut next_report = start + REPORT_EVERY;
111    let mut second = tokio::time::interval(Duration::from_secs(1));
112    while Instant::now() < end {
113        second.tick().await;
114        let now = version();
115        if now != seen {
116            counts.rewrites += 1;
117            counts.snapshot_bytes += now.map_or(0, |(_, len)| len);
118            seen = now;
119        }
120        if Instant::now() >= next_report {
121            counts.report(start.elapsed());
122            next_report += REPORT_EVERY;
123        }
124    }
125    counts.report(start.elapsed());
126
127    drop(admin);
128    runtime.shutdown_actor().await;
129    Ok(())
130}
Source

pub async fn allocate_namespace( &self, authorization: &AuthContext, ) -> Result<u64, AuthFailure>

Reserve a namespace that no key owns, for Self::issue_in_namespace.

A number is handed out once, ever. A caller that loses the response wastes it and asks again.

Source

pub async fn issue_in_namespace( &self, authorization: &AuthContext, namespace: u64, ttl: Duration, label: Option<String>, ) -> Result<IssuedTemporaryKey, AuthFailure>

Issue a key into a namespace from Self::allocate_namespace.

Every key in a namespace sees the same services and is revoked on its own. A namespace that was not allocated is refused, including another key’s own.

Source

pub async fn list( &self, authorization: &AuthContext, page: u32, page_size: u16, ) -> Result<KeyPage, AuthFailure>

Source

pub async fn show( &self, authorization: &AuthContext, key_id: KeyId, reveal: bool, ) -> Result<IssuedTemporaryKey, AuthFailure>

Source

pub async fn renew( &self, authorization: &AuthContext, key_id: KeyId, ttl: Duration, ) -> Result<IssuedTemporaryKey, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 240)
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
Source

pub async fn revoke( &self, authorization: &AuthContext, key_id: KeyId, ) -> Result<TemporaryKeyMetadata, AuthFailure>

Source

pub async fn gc(&self, authorization: &AuthContext) -> Result<u64, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 268)
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
Source

pub async fn reset( &self, authorization: &AuthContext, ) -> Result<(), AuthFailure>

Source

pub async fn rotate_root( &self, authorization: &AuthContext, new_key: AesKeyType, ) -> Result<(), AuthFailure>

Source

pub async fn set_legacy_protocol( &self, authorization: &AuthContext, policy: LegacyProtocolPolicy, ) -> Result<(), AuthFailure>

Source

pub async fn status( &self, authorization: &AuthContext, ) -> Result<AuthStatus, AuthFailure>

Examples found in repository?
examples/auth_bench.rs (line 250)
232async fn persistence(flavor: &'static str, probes: usize) -> BenchResult<()> {
233    let probes = Probes::start(probes);
234
235    let state_dir = TempPath::new("auth-bench-renew");
236    let (runtime, admin) = start(&state_dir, DEFAULT_TEMP_KEY_CAPACITY).await?;
237    let key_id = runtime.issue(&admin, HOUR, None).await?.metadata.key_id;
238    let mut timings = Timings::default();
239    for round in 0..RENEWALS + RENEWALS / 10 {
240        let (renewed, timing) = probes.measure(runtime.renew(&admin, key_id, HOUR)).await;
241        black_box(renewed?);
242        if round >= RENEWALS / 10 {
243            timings.push(timing);
244        }
245    }
246    timings.report(&format!("renew_{flavor}"));
247    // A command with no file work: what reaching the actor costs.
248    let mut timings = Timings::default();
249    for round in 0..RENEWALS + RENEWALS / 10 {
250        let (status, timing) = probes.measure(runtime.status(&admin)).await;
251        black_box(status?);
252        if round >= RENEWALS / 10 {
253            timings.push(timing);
254        }
255    }
256    timings.report(&format!("status_{flavor}"));
257    drop(admin);
258    runtime.shutdown_actor().await;
259
260    for capacity in [DEFAULT_TEMP_KEY_CAPACITY, MAX_TEMP_KEY_CAPACITY] {
261        let state_dir = TempPath::new("auth-bench-store");
262        let (runtime, admin) = start(&state_dir, capacity).await?;
263        for _ in 0..KEYS {
264            runtime.issue(&admin, HOUR, None).await?;
265        }
266        let mut timings = Timings::default();
267        for _ in 0..ROUNDS {
268            let (removed, timing) = probes.measure(runtime.gc(&admin)).await;
269            black_box(removed?);
270            timings.push(timing);
271        }
272        timings.report(&format!("gc{capacity}_{flavor}"));
273        drop(admin);
274        runtime.shutdown_actor().await;
275        // The handle holds the directory's lock too.
276        drop(runtime);
277
278        let mut timings = Timings::default();
279        for _ in 0..ROUNDS {
280            let (started, timing) = probes
281                .measure(AuthRuntime::start(
282                    TEST_ADMIN_KEY_BYTES,
283                    config(&state_dir, capacity),
284                ))
285                .await;
286            timings.push(timing);
287            started?.shutdown_actor().await;
288        }
289        timings.report(&format!("start{capacity}_{flavor}"));
290    }
291
292    probes.stop().await;
293    Ok(())
294}
Source

pub async fn audit_admin( &self, authorization: &AuthContext, action: impl Into<String>, key_id: Option<KeyId>, detail: Option<String>, ) -> Result<(), AuthFailure>

Trait Implementations§

Source§

impl Clone for AuthRuntime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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