Skip to content

Commit 09b086d

Browse files
committed
chore: more type foo
1 parent 283cbc0 commit 09b086d

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

crates/tx-cache/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl TxCache {
108108
.get(url)
109109
.send()
110110
.await
111-
.inspect_err(|e| warn!(%e, "Failed to get object from transaction cache"))?
111+
.inspect_err(|e| warn!(%e, "Failed to get object from transaction cache."))?
112112
.json::<T>()
113113
.await
114114
.map_err(Into::into)
@@ -168,7 +168,7 @@ impl TxCache {
168168
pub async fn get_transactions(
169169
&self,
170170
query: Option<PaginationParams<TxKey>>,
171-
) -> Result<CacheResponse<TxCacheTransactionsResponse, TxKey>, Error> {
171+
) -> Result<CacheResponse<TxCacheTransactionsResponse>, Error> {
172172
if let Some(query) = query {
173173
self.get_inner_with_query(TRANSACTIONS, query).await
174174
} else {
@@ -181,7 +181,7 @@ impl TxCache {
181181
pub async fn get_orders(
182182
&self,
183183
query: Option<PaginationParams<OrderKey>>,
184-
) -> Result<CacheResponse<TxCacheOrdersResponse, OrderKey>, Error> {
184+
) -> Result<CacheResponse<TxCacheOrdersResponse>, Error> {
185185
if let Some(query) = query {
186186
self.get_inner_with_query(ORDERS, query).await
187187
} else {

crates/tx-cache/src/types.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ pub trait CacheObject {
2121
/// A response from the transaction cache, containing an item.
2222
#[derive(Debug, Clone, Serialize, Deserialize)]
2323
#[serde(untagged)]
24-
pub enum CacheResponse<T, C: CursorKey> {
24+
pub enum CacheResponse<T: CacheObject>
25+
where
26+
T::Key: Serialize + for<'a> Deserialize<'a>,
27+
{
2528
/// A paginated response, containing the inner item and a pagination info.
2629
Paginated {
2730
/// The actual item.
2831
#[serde(flatten)]
2932
inner: T,
3033
/// The pagination info.
31-
pagination: PaginationInfo<C>,
34+
pagination: PaginationInfo<T::Key>,
3235
},
3336
/// An unpaginated response, containing the actual item.
3437
Unpaginated {
@@ -38,13 +41,19 @@ pub enum CacheResponse<T, C: CursorKey> {
3841
},
3942
}
4043

41-
impl<T, C: CursorKey> CacheObject for CacheResponse<T, C> {
42-
type Key = C;
44+
impl<T: CacheObject> CacheObject for CacheResponse<T>
45+
where
46+
T::Key: Serialize + for<'a> Deserialize<'a>,
47+
{
48+
type Key = T::Key;
4349
}
4450

45-
impl<T, C: CursorKey> CacheResponse<T, C> {
51+
impl<T: CacheObject> CacheResponse<T>
52+
where
53+
T::Key: Serialize + for<'a> Deserialize<'a>,
54+
{
4655
/// Create a new paginated response from a list of items and a pagination info.
47-
pub const fn paginated(inner: T, pagination: PaginationInfo<C>) -> Self {
56+
pub const fn paginated(inner: T, pagination: PaginationInfo<T::Key>) -> Self {
4857
Self::Paginated { inner, pagination }
4958
}
5059

@@ -70,7 +79,7 @@ impl<T, C: CursorKey> CacheResponse<T, C> {
7079
}
7180

7281
/// Return the pagination info, if any.
73-
pub const fn pagination_info(&self) -> Option<&PaginationInfo<C>> {
82+
pub const fn pagination_info(&self) -> Option<&PaginationInfo<T::Key>> {
7483
match self {
7584
Self::Paginated { pagination, .. } => Some(pagination),
7685
Self::Unpaginated { .. } => None,
@@ -96,15 +105,15 @@ impl<T, C: CursorKey> CacheResponse<T, C> {
96105
}
97106

98107
/// Consume the response and return the parts.
99-
pub fn into_parts(self) -> (T, Option<PaginationInfo<C>>) {
108+
pub fn into_parts(self) -> (T, Option<PaginationInfo<T::Key>>) {
100109
match self {
101110
Self::Paginated { inner, pagination } => (inner, Some(pagination)),
102111
Self::Unpaginated { inner } => (inner, None),
103112
}
104113
}
105114

106115
/// Consume the response and return the pagination info, if any.
107-
pub fn into_pagination_info(self) -> Option<PaginationInfo<C>> {
116+
pub fn into_pagination_info(self) -> Option<PaginationInfo<T::Key>> {
108117
match self {
109118
Self::Paginated { pagination, .. } => Some(pagination),
110119
Self::Unpaginated { .. } => None,

0 commit comments

Comments
 (0)