Skip to content

Commit 59ff5a6

Browse files
committed
Replace ux_serde with ux
The `ux_serde` crate is rather unmaintained, and for now we can just handroll the serde impls. If that's too much boilerplate we can switch to using a macro or a newtype wrapper.
1 parent c943a54 commit 59ff5a6

File tree

8 files changed

+54
-21
lines changed

8 files changed

+54
-21
lines changed

Cargo.lock

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/opsqueue_python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ uuid = {version = "1.11.0", features = [
1919
"fast-rng", # Use a faster (but still sufficiently random) RNG
2020
]}
2121
chrono = { version = "0.4.38"}
22-
ux_serde = { version = "0.2.0", features = ["std"] }
22+
ux = "0.1.6"
2323

2424
# Concurrency:
2525
tokio = {version = "1.38", features = ["macros", "rt-multi-thread"]}

libs/opsqueue_python/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use pyo3::prelude::*;
1111

1212
use opsqueue::common::{chunk, submission};
1313
use opsqueue::consumer::strategy;
14-
use ux_serde::u63;
14+
use ux::u63;
1515

1616
use crate::errors::{CError, CPyResult, FatalPythonException};
1717

libs/opsqueue_python/src/producer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use opsqueue::{
2020
tracing::CarrierMap,
2121
E,
2222
};
23-
use ux_serde::u63;
23+
use ux::u63;
2424

2525
use crate::{
2626
async_util,

opsqueue/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ uuid = {version = "1.11.0", features = [
2929
"fast-rng", # Use a faster (but still sufficiently random) RNG
3030
"serde",
3131
]}
32+
ux = "0.1.6"
3233
# Error handling:
3334
anyhow = "1.0.86"
3435
# Database:
@@ -64,7 +65,6 @@ moro-local = "0.4.0"
6465
thiserror = "1.0.65"
6566
either = "1.13.0"
6667
serde-error = "0.1.3"
67-
ux_serde = { version = "0.2.0", features = ["std", "serde"] }
6868
backon = { version = "1.3.0", features = ["tokio-sleep"] }
6969
rand = "0.8.5"
7070
rustc-hash = "2.0.0"

opsqueue/src/common/chunk.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
use chrono::{DateTime, Utc};
77

88
use serde::{Deserialize, Serialize};
9-
use ux_serde::u63;
9+
use ux::u63;
1010

1111
use super::errors::TryFromIntError;
1212
use super::submission::SubmissionId;
1313

1414
/// Index of this particular chunk in a submission.
15-
#[derive(
16-
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
17-
)]
15+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1816
pub struct ChunkIndex(u63);
1917

2018
impl std::fmt::Debug for ChunkIndex {
@@ -23,6 +21,26 @@ impl std::fmt::Debug for ChunkIndex {
2321
}
2422
}
2523

24+
impl serde::Serialize for ChunkIndex {
25+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
26+
where
27+
S: serde::Serializer,
28+
{
29+
u64::from(*self).serialize(serializer)
30+
}
31+
}
32+
33+
impl<'a> serde::Deserialize<'a> for ChunkIndex {
34+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
35+
where
36+
D: serde::Deserializer<'a>,
37+
{
38+
let value = u64::deserialize(deserializer)?;
39+
40+
value.try_into().map_err(serde::de::Error::custom)
41+
}
42+
}
43+
2644
/// Another name for ChunkIndex, indicating that we're dealing with the _total count_ of chunks.
2745
/// i.e. when you have a value of type ChunkCount, there is a high likelyhood
2846
/// that there are [0..chunk_count) (note the half-open range) chunks to select from.

opsqueue/src/common/submission.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt::Display;
33
use std::time::Duration;
44

55
use chrono::{DateTime, Utc};
6-
use ux_serde::u63;
6+
use ux::u63;
77

88
use super::chunk::{self, Chunk, ChunkFailed, ChunkSize};
99
use super::chunk::{ChunkCount, ChunkIndex};
@@ -16,11 +16,29 @@ static ID_GENERATOR: snowflaked::sync::Generator = snowflaked::sync::Generator::
1616
///
1717
/// Submission IDs are snowflakes. These are 64-bit identifiers that includes
1818
/// creation time information and are sortable on that timestamp.
19-
#[derive(
20-
Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
21-
)]
19+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2220
pub struct SubmissionId(u63);
2321

22+
impl serde::Serialize for SubmissionId {
23+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
24+
where
25+
S: serde::Serializer,
26+
{
27+
u64::from(*self).serialize(serializer)
28+
}
29+
}
30+
31+
impl<'a> serde::Deserialize<'a> for SubmissionId {
32+
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
33+
where
34+
D: serde::Deserializer<'a>,
35+
{
36+
let value = u64::deserialize(deserializer)?;
37+
38+
value.try_into().map_err(serde::de::Error::custom)
39+
}
40+
}
41+
2442
impl Default for SubmissionId {
2543
fn default() -> Self {
2644
Self::new()

opsqueue/src/object_store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use futures::stream::{self, TryStreamExt};
55
use object_store::path::Path;
66
use object_store::DynObjectStore;
77
use reqwest::Url;
8-
use ux_serde::u63;
8+
use ux::u63;
99

1010
/// A client for interacting with an object store.
1111
///

0 commit comments

Comments
 (0)