Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

chore(soup): replace custom either with axum_extra either (#975)

Sean Aye917555013e07
diff --git a/rust/cloud-storage/models_pagination/src/axum.rs b/rust/cloud-storage/models_pagination/src/axum.rs
index 0beeb68e00..25fa58f6b4 100644
--- a/rust/cloud-storage/models_pagination/src/axum.rs
+++ b/rust/cloud-storage/models_pagination/src/axum.rs
@@ -2,8 +2,7 @@ use crate::{Base64SerdeErr, Base64Str, Cursor, CursorVal, CursorWithValAndFilter
use axum::extract::{FromRequestParts, Query};
use axum::http::{StatusCode, request::Parts};
use axum::response::IntoResponse;
-use axum::{Json, RequestPartsExt, async_trait};
-pub use either::Either;
+use axum::{Json, async_trait};
use model_error_response::ErrorResponse;
use serde::Deserialize;
use serde::de::DeserializeOwned;
@@ -117,44 +116,3 @@ where
Ok(CursorExtractor::Some(decoded))
}
}
-
-/// utility type for handling the cases where exactly 1 of 2 extractors must pass
-pub struct EitherWrapper<L, R>(pub Either<L, R>);
-
-impl<L, R> IntoResponse for EitherWrapper<L, R>
-where
- L: IntoResponse,
- R: IntoResponse,
-{
- fn into_response(self) -> axum::response::Response {
- match self.0 {
- Either::Left(l) => l.into_response(),
- Either::Right(r) => r.into_response(),
- }
- }
-}
-
-#[axum::async_trait]
-impl<S, L, R> FromRequestParts<S> for EitherWrapper<L, R>
-where
- L: FromRequestParts<S> + Send + 'static,
- L::Rejection: Send,
- R: FromRequestParts<S> + Send + 'static,
- R::Rejection: Send,
- S: Send + Sync,
-{
- type Rejection = EitherWrapper<L::Rejection, R::Rejection>;
-
- async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
- let res: Result<L, _> = parts.extract_with_state(state).await;
- if let Ok(left) = res {
- return Ok(EitherWrapper(Either::Left(left)));
- }
- let res2: Result<R, _> = parts.extract_with_state(state).await;
-
- res2.map(Either::Right)
- .map(EitherWrapper)
- .map_err(Either::Right)
- .map_err(EitherWrapper)
- }
-}
diff --git a/rust/cloud-storage/soup/src/inbound/axum_router.rs b/rust/cloud-storage/soup/src/inbound/axum_router.rs
index 676b08d333..bc36d49436 100644
--- a/rust/cloud-storage/soup/src/inbound/axum_router.rs
+++ b/rust/cloud-storage/soup/src/inbound/axum_router.rs
@@ -9,7 +9,7 @@ use axum::{
response::IntoResponse,
routing::{get, post},
};
-use axum_extra::extract::Cached;
+use axum_extra::{either::Either, extract::Cached};
use email::{
domain::{
models::{Link, PreviewView},
@@ -25,8 +25,7 @@ use macro_user_id::user_id::MacroUserIdStr;
use model_error_response::ErrorResponse;
use model_user::axum_extractor::MacroUserExtractor;
use models_pagination::{
- CursorExtractor, Either, EitherWrapper, Frecency, PaginatedOpaqueCursor, SimpleSortMethod,
- SortMethod, TypeEraseCursor,
+ CursorExtractor, Frecency, PaginatedOpaqueCursor, SimpleSortMethod, SortMethod, TypeEraseCursor,
};
use models_soup::item::SoupItem;
use serde::{Deserialize, Serialize};
@@ -140,13 +139,13 @@ where
}
};
- let cursor = match cursor.0 {
- Either::Left(l) => l
+ let cursor = match cursor {
+ Either::E1(l) => l
.into_option()
.map(models_pagination::Query::Cursor)
.map(SoupQuery::Simple)
.unwrap_or_else(create_fallback),
- Either::Right(r) => r
+ Either::E2(r) => r
.into_option()
.map(models_pagination::Query::Cursor)
.map(SoupQuery::Frecency)
@@ -287,7 +286,7 @@ pub struct PostSoupRequest {
email_view: PreviewView,
}
-type SoupCursor = EitherWrapper<
+type SoupCursor = axum_extra::either::Either<
CursorExtractor<Uuid, SimpleSortMethod, Option<EntityFilterAst>>,
CursorExtractor<Uuid, Frecency, Option<EntityFilterAst>>,
>;