Skip to content

Commit 0d6c4ca

Browse files
sjuddConvex, Inc.
authored and
Convex, Inc.
committed
Remove a bunch of unecessary fallible conversions (#24678)
GitOrigin-RevId: 25c1bf89e85737c0f0c36af88bc0f54d6d30dd9f
1 parent 469c948 commit 0d6c4ca

File tree

7 files changed

+12
-22
lines changed

7 files changed

+12
-22
lines changed

crates/common/src/bootstrap_model/index/vector_index/backfill_state.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ impl TryFrom<VectorIndexBackfillState> for SerializedVectorIndexBackfillState {
4545
.collect::<anyhow::Result<Vec<_>>>()?,
4646
),
4747
document_cursor: backfill_state.cursor.map(|id| id.to_string()),
48-
backfill_snapshot_ts: backfill_state
49-
.backfill_snapshot_ts
50-
.map(|ts| ts.try_into())
51-
.transpose()?,
48+
backfill_snapshot_ts: backfill_state.backfill_snapshot_ts.map(|ts| ts.into()),
5249
})
5350
}
5451
}

crates/common/src/bootstrap_model/index/vector_index/segment.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ impl TryFrom<FragmentedVectorSegment> for pb::searchlight::FragmentedVectorSegme
119119

120120
fn try_from(value: FragmentedVectorSegment) -> Result<Self, Self::Error> {
121121
Ok(Self {
122-
segment_key: value.segment_key.try_into()?,
123-
id_tracker_key: value.id_tracker_key.try_into()?,
124-
deleted_bitset_key: value.deleted_bitset_key.try_into()?,
122+
segment_key: value.segment_key.into(),
123+
id_tracker_key: value.id_tracker_key.into(),
124+
deleted_bitset_key: value.deleted_bitset_key.into(),
125125
num_vectors: value.num_vectors,
126126
num_deleted: value.num_deleted,
127127
id: value.id,

crates/common/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl TryFrom<JsError> for JsErrorProto {
362362
message: Some(message),
363363
custom_data: custom_data
364364
.map(|v| {
365-
let json = JsonValue::try_from(v)?;
365+
let json = JsonValue::from(v);
366366
anyhow::Ok::<Vec<u8>>(serde_json::to_vec(&json)?)
367367
})
368368
.transpose()?,

crates/common/src/log_streaming.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub struct LogEvent {
5858
impl LogEvent {
5959
pub fn default_for_verification<RT: Runtime>(runtime: &RT) -> anyhow::Result<Self> {
6060
let mut payload = serde_json::Map::new();
61-
payload.insert("message".to_string(), "Convex connection test".try_into()?);
61+
payload.insert("message".to_string(), "Convex connection test".into());
6262
Ok(Self {
6363
topic: LogTopic::Verification,
6464
source: EventSource::System,
@@ -124,16 +124,16 @@ impl TryFrom<LogEvent> for serde_json::Map<String, JsonValue> {
124124
// Global system fields
125125
fields.insert("_topic".to_string(), event.topic.try_into()?);
126126
let ms = event.timestamp.as_ms_since_epoch()?;
127-
fields.insert("_timestamp".to_string(), ms.try_into()?);
127+
fields.insert("_timestamp".to_string(), ms.into());
128128
// Source system fields
129129
match event.source {
130130
EventSource::Function(f) => {
131-
fields.insert("_functionPath".to_string(), f.path.try_into()?);
131+
fields.insert("_functionPath".to_string(), f.path.into());
132132
fields.insert(
133133
"_functionType".to_string(),
134134
serde_json::to_value(f.udf_type)?,
135135
);
136-
fields.insert("_functionCached".to_string(), f.cached.try_into()?);
136+
fields.insert("_functionCached".to_string(), f.cached.into());
137137
},
138138
EventSource::System => {},
139139
}

crates/common/src/schemas/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl TryFrom<ConvexValue> for DatabaseSchema {
116116
type Error = anyhow::Error;
117117

118118
fn try_from(v: ConvexValue) -> anyhow::Result<Self> {
119-
JsonValue::try_from(v)?.try_into()
119+
JsonValue::from(v).try_into()
120120
}
121121
}
122122

crates/value/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ impl From<ConvexObject> for ConvexValue {
204204

205205
impl From<ResolvedDocumentId> for ConvexValue {
206206
fn from(value: ResolvedDocumentId) -> Self {
207-
DocumentIdV6::try_from(value)
208-
.expect("Could not create IDV6 from DocumentId")
209-
.into()
207+
DocumentIdV6::from(value).into()
210208
}
211209
}
212210

crates/value/src/sha256.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,7 @@ impl Sha256 {
117117
}
118118

119119
pub fn finalize(self) -> Sha256Digest {
120-
Sha256Digest(
121-
self.inner
122-
.finalize()
123-
.try_into()
124-
.expect("Sha256 wasn't 32 bytes?"),
125-
)
120+
Sha256Digest(self.inner.finalize().into())
126121
}
127122
}
128123

0 commit comments

Comments
 (0)