@@ -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