···5656 /// Panics if `micros` is greater than [`Self::MAX_TIMESTAMP`].5757 ///5858 pub const fn set_micros(&mut self, micros: u64) {5959- if micros > Self::MAX_TIMESTAMP {6060- panic!("TID timestamp must be in the range 0..=9007199254740991 microseconds");6161- }5959+ assert!(micros <= Self::MAX_TIMESTAMP, "TID timestamp must be in the range 0..=9007199254740991 microseconds");6260 self.0 |= (micros & MASK_TIMESTAMP) << BITS_CLOCK_ID;6361 }6462···6769 /// Panics if `clock_id` is greater than [`Self::MAX_CLOCK_ID`].6870 ///6971 pub const fn set_clock_id(&mut self, clock_id: u16) {7070- if clock_id > Self::MAX_CLOCK_ID {7171- panic!("TID clock ID must be in the range 0..=1023");7272- }7373- self.0 |= (clock_id as u64) & MASK_CLOCK_ID7272+ assert!(clock_id <= Self::MAX_CLOCK_ID, "TID clock ID must be in the range 0..=1023");7373+ self.0 |= (clock_id as u64) & MASK_CLOCK_ID;7474 }75757676 /// Create a new TID with the specified timestamp and clock ID.···8084 /// * `micros` exceeds [`Self::MAX_TIMESTAMP`].8185 /// * `clock_id` exceeds [`Self::MAX_CLOCK_ID`]8286 ///8787+ #[must_use] 8388 pub const fn new(micros: u64, clock_id: u16) -> Self {8484- let mut new = Tid(0);8989+ let mut new = Self(0);8590 new.set_micros(micros);8691 new.set_clock_id(clock_id);8792 new···106109 /// * `seconds` exceeds [`Self::MAX_TIMESTAMP`] when converted to microseconds.107110 /// * `clock_id` exceeds [`Self::MAX_CLOCK_ID`]108111 ///112112+ #[must_use] 109113 pub const fn from_secs(seconds: u64, clock_id: u16) -> Self {110114 Self::new(seconds * 1_000_000, clock_id)111115 }···142144 /// assert_eq!(Tid::MAX.micros(), 9007199254740991);143145 /// ```144146 ///145145- pub fn micros(&self) -> u64 {147147+ #[must_use] 148148+ pub const fn micros(&self) -> u64 {146149 (self.0 >> BITS_CLOCK_ID) & Self::MAX_TIMESTAMP147150 }148151···155156 /// assert_eq!(Tid::MAX.clock_id(), 1023);156157 /// ```157158 ///158158- pub fn clock_id(&self) -> u16 {159159+ #[must_use] 160160+ pub const fn clock_id(&self) -> u16 {159161 // CONVERSION: Clock ID mask ensures this will always produce an equivalent u16.160162 (self.0 & MASK_CLOCK_ID) as _161163 }···190190 ///191191 pub fn set_datetime(&mut self, dt: time::OffsetDateTime) {192192 let micros = dt.unix_timestamp_nanos() / 1000;193193- self.set_micros(micros.try_into().unwrap())193193+ self.set_micros(micros.try_into().unwrap());194194 }195195196196 /// Create a TID from the specified [`time::OffsetDateTime`] and clock ID.···199199 ///200200 /// Panics if `dt` is later than 2255-06-05 23:47:34.740991 +00:00:00.201201 ///202202+ #[must_use] 202203 pub fn from_datetime(dt: time::OffsetDateTime, clock_id: u16) -> Self {203204 let micros = dt.unix_timestamp_nanos() / 1000;204205 Self::new(micros.try_into().unwrap(), clock_id)205206 }206207207208 /// Convert the TID to a [`time::OffsetDateTime`]209209+ #[must_use] 208210 pub fn as_datetime(&self) -> time::OffsetDateTime {209211 time::OffsetDateTime::from_unix_timestamp_nanos(self.nanos())210212 .expect("2^53 microseconds is less than MAX for OffsetDateTime")···311309312310impl TidClock {313311 /// Create a new TID clock with the specified ID.312312+ #[must_use] 314313 pub const fn with_id(clock_id: u16) -> Self {315315- if clock_id > Tid::MAX_CLOCK_ID {316316- panic!("TID clock ID must be in the range 0..=1023");317317- }314314+ assert!(clock_id <= Tid::MAX_CLOCK_ID, "TID clock ID must be in the range 0..=1023");318315319316 Self {320317 id: clock_id,
···9999 account_did.if_supports_color(Stderr, |text| text.green())100100 );101101102102- if !self.method.contains(&"ssh".to_string()) {103103- panic!("unsupported method");104104- }102102+ assert!(self.method.contains(&"ssh".to_string()), "unsupported method");105103106104 // Build a list of the public keys associated with the current active DID.107105 let empty = HashSet::new();
+1-1
crates/credential-helper/src/main.rs
···22mod config;3344use clap::{Parser, Subcommand};55-use commands::*;55+use commands::{Auth, GitCredential, GitSetup};66use tracing_subscriber::{EnvFilter, layer::SubscriberExt as _, util::SubscriberInitExt as _};7788pub trait RunCommand {
···29293030 /// Repository DIDs to filter which records are received.3131 ///3232- /// Maximum: 10_0003232+ /// Maximum: `10_000`3333 pub wanted_dids: HashSet<OwnedDid>,34343535 /// Maximum message size in bytes the subscriber wants to receive.···8080 }81818282 /// Get the normalized maximum message size.8383+ #[must_use] 8384 pub fn max_message_size(&self) -> i64 {8485 normalize_max_message_size(self.max_message_size_bytes)8586 }86878788 /// Construct the Jetstream subscribe URL, returning a tuple of the URL and a boolean8889 /// indicating whether the client should send an options update message on connect.9090+ #[must_use] 8991 pub fn subscribe_url(&self, url: &url::Url) -> (url::Url, bool) {9092 let mut url = url.to_owned();9193 url.set_path("/subscribe");···123121 (url, false)124122 }125123126126- /// Present the SubscriberOptions as a [`SubscriberSourcedMessage`] for serialization.127127- pub fn as_subscriber_sourced_message<'a>(&'a self) -> SubscriberSourcedMessage<'a> {124124+ /// Present the `SubscriberOptions` as a [`SubscriberSourcedMessage`] for serialization.125125+ #[must_use] 126126+ pub fn as_subscriber_sourced_message(&self) -> SubscriberSourcedMessage<'_> {128127 SubscriberSourcedMessage::OptionsUpdate(self.into())129128 }130129···174171 }175172}176173177177-fn normalize_max_message_size(value: i64) -> i64 {174174+const fn normalize_max_message_size(value: i64) -> i64 {178175 value.abs()179176}180177···188185 OptionsUpdate(OptionsUpdate<'a>),189186}190187191191-impl<'a> SubscriberSourcedMessage<'a> {188188+impl SubscriberSourcedMessage<'_> {192189 /// Serialize the [`SubscriberSourcedMessage`] to JSON.190190+ #[must_use] 193191 pub fn to_json(&self) -> String {194192 serde_json::to_string(self).expect("SubscriberSourcedMessage should be serializable")195193 }
+4-7
crates/jetstream/src/task.rs
···58585959impl Jitter for f32 {6060 fn jitter(&self, frac: f32) -> Self {6161- self * (1.0 + 2.0 * frac * (fastrand::f32() - 0.5))6161+ self * (2.0 * frac).mul_add(fastrand::f32() - 0.5, 1.0)6262 }6363}64646565impl Jitter for Duration {6666 fn jitter(&self, frac: f32) -> Self {6767- Duration::from_secs_f32(self.as_secs_f32().jitter(frac).abs())6767+ Self::from_secs_f32(self.as_secs_f32().jitter(frac).abs())6868 }6969}7070···212212 state.metrics.modify(|mut data| data.messages_received += 1);213213 if let Err(error) = event_tx.send_async(message).await {214214 let payload = error.into_inner();215215- match std::str::from_utf8(&payload) {216216- Ok(payload) => tracing::error!(%payload, "Failed to dispatch event to channel"),217217- Err(_) => tracing::error!(?payload, "Failed to dispatch event to channel"),218218- }215215+ if let Ok(payload) = std::str::from_utf8(&payload) { tracing::error!(%payload, "Failed to dispatch event to channel") } else { tracing::error!(?payload, "Failed to dispatch event to channel") }219216 break 'outer;220217 }221218···326329fn rewind_cursor(options: &Mutex<SubscriberOptions>, amount: Duration) {327330 let mut options = options.lock().unwrap();328331 if let Some(value) = &mut options.cursor {329329- *value = value.saturating_sub(amount.as_micros())332332+ *value = value.saturating_sub(amount.as_micros());330333 }331334}332335
+1-1
crates/knot/src/cli.rs
···86868787impl Arguments {8888 pub fn to_knot_config(&self) -> Result<KnotConfiguration, Error> {8989- let Arguments {8989+ let Self {9090 name,9191 owner,9292 repos: repo_path,
+4-7
crates/knot/src/main.rs
···7373 assert!(git_config_global_set("core.hooksPath", &arguments.hooks)?);7474 assert!(git_config_global_set(7575 "receive.advertisePushOptions",7676- match arguments.require_signed_push {7777- true => "true",7878- false => "false",7979- }7676+ if arguments.require_signed_push { "true" } else { "false" }8077 )?);81788279 let database = {···122125 // The knot needs to know the sockets we've bound the private API.123126 let private_addrs = private_listeners124127 .iter()125125- .map(|listener| listener.local_addr())128128+ .map(tokio::net::TcpListener::local_addr)126129 .collect::<Result<Vec<_>, std::io::Error>>()?;127130128131 tracing::info!(?private_addrs, "bound internal API");···205208 let mut sigterm = signal::unix::signal(SignalKind::terminate())?;206209207210 tokio::select! {208208- Ok(_) = signal::ctrl_c() => {211211+ Ok(()) = signal::ctrl_c() => {209212 eprintln!();210213 tracing::info!("ctrl+c received, shutting down ...");211214 },212212- Some(_) = sigterm.recv() => {215215+ Some(()) = sigterm.recv() => {213216 tracing::info!("SIGTERM received, shutting down ...");214217 }215218 }