Skip to content

Commit 3493eea

Browse files
committed
chore: migrate to Rust 2024 edition
1 parent 101cd45 commit 3493eea

File tree

13 files changed

+117
-97
lines changed

13 files changed

+117
-97
lines changed

.config/flakebox/id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
37774156368d8943a21a97587bb2bac2aa703cc24decd367aa4550b272380ce470bc74dbb3691afe1994f0261ca4577ff390022c71427450e5f94f4236a076c8
1+
bf1c5bb145b268ccfcb2e00cb7b001c33f153d196cd25de9108e95a6526bfb3a59570e5c06efb1d5984b4a65cf94de18cd50fa2bac2003ea0b087ce06d5ec119

.rustfmt.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ group_imports = "StdExternalCrate"
22
wrap_comments = true
33
format_code_in_doc_comments = true
44
imports_granularity = "Module"
5-
edition = "2021"
5+
edition = "2024"

crates/rostra-client-db/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,12 +534,15 @@ impl Database {
534534
}
535535

536536
pub fn verify_self_tx(self_id: RostraId, ids_self_t: &mut ids_self::Table) -> DbResult<()> {
537-
if let Some(existing_self_id_record) = Self::read_self_id_tx(ids_self_t)? {
538-
if existing_self_id_record.rostra_id != self_id {
539-
return DbIdMismatchSnafu.fail();
537+
match Self::read_self_id_tx(ids_self_t)? {
538+
Some(existing_self_id_record) => {
539+
if existing_self_id_record.rostra_id != self_id {
540+
return DbIdMismatchSnafu.fail();
541+
}
542+
}
543+
_ => {
544+
Self::write_self_id_tx(self_id, ids_self_t)?;
540545
}
541-
} else {
542-
Self::write_self_id_tx(self_id, ids_self_t)?;
543546
};
544547
Ok(())
545548
}

crates/rostra-client-db/src/tx_ops.rs

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,28 @@ impl Database {
188188
let (id_short, id_rest) = event.author().split();
189189
ids_full_t.insert(&id_short, &id_rest)?;
190190

191-
let (was_missing, is_deleted) = if let Some(prev_missing) = events_missing_table
191+
let (was_missing, is_deleted) = match events_missing_table
192192
.remove(&(author, event_id))?
193193
.map(|g| g.value())
194194
{
195-
// if the missing was marked as deleted, we'll record it
196-
(
197-
true,
198-
if let Some(deleted_by) = prev_missing.deleted_by {
199-
events_content_table
200-
.insert(&event_id, &EventContentState::Deleted { deleted_by })?;
201-
true
202-
} else {
203-
false
204-
},
205-
)
206-
} else {
207-
// since nothing was expecting this event yet, it must be a "head"
208-
events_heads_table.insert(&(author, event_id), &EventsHeadsTableRecord)?;
209-
(false, false)
195+
Some(prev_missing) => {
196+
// if the missing was marked as deleted, we'll record it
197+
(
198+
true,
199+
if let Some(deleted_by) = prev_missing.deleted_by {
200+
events_content_table
201+
.insert(&event_id, &EventContentState::Deleted { deleted_by })?;
202+
true
203+
} else {
204+
false
205+
},
206+
)
207+
}
208+
_ => {
209+
// since nothing was expecting this event yet, it must be a "head"
210+
events_heads_table.insert(&(author, event_id), &EventsHeadsTableRecord)?;
211+
(false, false)
212+
}
210213
};
211214

212215
// When both parents point at same thing, process only one: one that can
@@ -481,7 +484,7 @@ impl Database {
481484
) -> DbResult<IdSelfAccountRecord> {
482485
let id_self_record = IdSelfAccountRecord {
483486
rostra_id: self_id,
484-
iroh_secret: thread_rng().gen(),
487+
iroh_secret: thread_rng().r#gen(),
485488
};
486489
let _ = id_self_table.insert(&(), &id_self_record)?;
487490
Ok(id_self_record)
@@ -523,21 +526,25 @@ impl Database {
523526
let before_pivot = (ShortEventId::ZERO)..(pivot);
524527
let after_pivot = (pivot)..=(ShortEventId::MAX);
525528

526-
Ok(Some(if thread_rng().gen() {
527-
if let Some(k) = get_first_in_range(events_self_table, after_pivot)? {
528-
k
529-
} else if let Some(k) = get_last_in_range(events_self_table, before_pivot)? {
530-
k
531-
} else {
532-
return Ok(None);
529+
Ok(Some(if thread_rng().r#gen() {
530+
match get_first_in_range(events_self_table, after_pivot)? {
531+
Some(k) => k,
532+
_ => match get_last_in_range(events_self_table, before_pivot)? {
533+
Some(k) => k,
534+
_ => {
535+
return Ok(None);
536+
}
537+
},
533538
}
534539
} else {
535-
if let Some(k) = get_first_in_range(events_self_table, before_pivot)? {
536-
k
537-
} else if let Some(k) = get_last_in_range(events_self_table, after_pivot)? {
538-
k
539-
} else {
540-
return Ok(None);
540+
match get_first_in_range(events_self_table, before_pivot)? {
541+
Some(k) => k,
542+
_ => match get_last_in_range(events_self_table, after_pivot)? {
543+
Some(k) => k,
544+
_ => {
545+
return Ok(None);
546+
}
547+
},
541548
}
542549
}))
543550
}

crates/rostra-client/src/client.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,12 @@ impl Client {
165165
let endpoint = Self::make_iroh_endpoint(db.as_ref().map(|s| s.iroh_secret())).await?;
166166
let (check_for_updates_tx, _) = watch::channel(());
167167

168-
let db = if let Some(db) = db {
169-
db
170-
} else {
171-
debug!(target: LOG_TARGET, id = %id, "Creating temporary in-memory database");
172-
Database::new_in_memory(id).await?
168+
let db = match db {
169+
Some(db) => db,
170+
_ => {
171+
debug!(target: LOG_TARGET, id = %id, "Creating temporary in-memory database");
172+
Database::new_in_memory(id).await?
173+
}
173174
}
174175
.into();
175176
trace!(target: LOG_TARGET, id = %id, "Creating client");
@@ -225,10 +226,13 @@ impl Client {
225226
{
226227
debug!(target: LOG_TARGET, "Existing node announcement found");
227228
} else {
228-
if let Err(err) = self.publish_node_announcement(id_secret).await {
229-
warn!(target: LOG_TARGET, err = %err.fmt_compact(), "Could not publish node announcement");
230-
} else {
231-
info!(target: LOG_TARGET, "Published node announcement");
229+
match self.publish_node_announcement(id_secret).await {
230+
Err(err) => {
231+
warn!(target: LOG_TARGET, err = %err.fmt_compact(), "Could not publish node announcement");
232+
}
233+
_ => {
234+
info!(target: LOG_TARGET, "Published node announcement");
235+
}
232236
}
233237
}
234238

crates/rostra-core/src/rand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ impl rand::distributions::Distribution<ShortEventId> for rand::distributions::St
1313
impl ShortEventId {
1414
pub fn random() -> Self {
1515
let mut csprng = OsRng;
16-
csprng.gen()
16+
csprng.r#gen()
1717
}
1818
}

crates/rostra-p2p/src/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub trait RpcRequest: RpcMessage {}
120120
pub trait RpcResponse: RpcMessage {}
121121

122122
macro_rules! define_rpc {
123-
($id:expr, $req:ident, $req_body:item, $resp:ident, $resp_body:item) => {
123+
($id:expr_2021, $req:ident, $req_body:item, $resp:ident, $resp_body:item) => {
124124

125125
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
126126
#[derive(Encode, Decode, Clone, Debug)]

crates/rostra-web-ui/src/asset_cache.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ impl AssetCache {
8787
filename.to_string(),
8888
StaticAsset {
8989
path: stored_path,
90-
raw: if let Some(compressed) = compressed.as_ref() {
90+
raw: match compressed.as_ref() { Some(compressed) => {
9191
// if we have compressed copy, don't store raw data
9292
// decompress the raw one one the fly if anyone actually asks
9393
let compressed = compressed.clone();
9494
LazyLock::new(Box::new(move || {
9595
debug!(target: LOG_TARGET, "Decompressing raw data from compressed version");
9696
Bytes::from(decompress_data(&compressed))
9797
}))
98-
} else {
98+
} _ => {
9999
LazyLock::new(Box::new(|| Bytes::from(raw)))
100-
},
100+
}},
101101
compressed,
102102
},
103103
)))

crates/rostra-web-ui/src/error.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,36 @@ impl IntoResponse for RequestError {
9292
fn into_response(self) -> Response {
9393
info!(err=%self, "Request Error");
9494

95-
let (status_code, message) = if let Some(user_err) =
96-
root_cause(&self).downcast_ref::<UserRequestError>()
97-
{
98-
return user_err.into_response();
99-
} else {
100-
match self {
101-
RequestError::StateClient { .. } => {
102-
return Redirect::temporary("/ui/unlock").into_response();
103-
}
104-
RequestError::LoginRequired => {
105-
let headers = [
106-
(
107-
HeaderName::from_static("hx-redirect"),
108-
HeaderValue::from_static("/ui/unlock"),
109-
),
110-
(
111-
HeaderName::from_static("location"),
112-
HeaderValue::from_static("/ui/unlock"),
113-
),
114-
];
115-
return (StatusCode::SEE_OTHER, headers).into_response();
95+
let (status_code, message) = match root_cause(&self).downcast_ref::<UserRequestError>() {
96+
Some(user_err) => {
97+
return user_err.into_response();
98+
}
99+
_ => {
100+
match self {
101+
RequestError::StateClient { .. } => {
102+
return Redirect::temporary("/ui/unlock").into_response();
103+
}
104+
RequestError::LoginRequired => {
105+
let headers = [
106+
(
107+
HeaderName::from_static("hx-redirect"),
108+
HeaderValue::from_static("/ui/unlock"),
109+
),
110+
(
111+
HeaderName::from_static("location"),
112+
HeaderValue::from_static("/ui/unlock"),
113+
),
114+
];
115+
return (StatusCode::SEE_OTHER, headers).into_response();
116116

117-
// return Redirect::temporary("/ui/unlock").into_response();
117+
// return Redirect::temporary("/ui/unlock").
118+
// into_response();
119+
}
120+
_ => (
121+
StatusCode::INTERNAL_SERVER_ERROR,
122+
"Internal Service Error".to_owned(),
123+
),
118124
}
119-
_ => (
120-
StatusCode::INTERNAL_SERVER_ERROR,
121-
"Internal Service Error".to_owned(),
122-
),
123125
}
124126
};
125127

crates/rostra-web-ui/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ pub struct UiState {
9898

9999
impl UiState {
100100
pub async fn client(&self, id: RostraId) -> UiStateClientResult<ClientHandle> {
101-
if let Some(handle) = self.clients.get(id).await {
102-
Ok(handle)
103-
} else {
104-
ClientNotLoadedSnafu.fail()
101+
match self.clients.get(id).await {
102+
Some(handle) => Ok(handle),
103+
_ => ClientNotLoadedSnafu.fail(),
105104
}
106105
}
107106

@@ -224,13 +223,16 @@ impl Server {
224223
);
225224
let mut router = Router::new().merge(routes::route_handler(self.state.clone()));
226225

227-
if let Some(assets) = self.assets {
228-
router = router.nest("/assets", routes::static_file_handler(assets));
229-
} else {
230-
router = router.nest_service(
231-
"/assets",
232-
ServeDir::new(format!("{}/assets", env!("CARGO_MANIFEST_DIR"))),
233-
);
226+
match self.assets {
227+
Some(assets) => {
228+
router = router.nest("/assets", routes::static_file_handler(assets));
229+
}
230+
_ => {
231+
router = router.nest_service(
232+
"/assets",
233+
ServeDir::new(format!("{}/assets", env!("CARGO_MANIFEST_DIR"))),
234+
);
235+
}
234236
}
235237

236238
let session_store = MemoryStore::default();

0 commit comments

Comments
 (0)