Skip to content

Commit

Permalink
Some clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
akoshelev committed Mar 25, 2024
1 parent 741c052 commit d029c6f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
24 changes: 13 additions & 11 deletions ipa-core/src/helpers/transport/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ use crate::{
},
};

/// Represents some response sent from MPC helper acting on a given request. It is rudimental now
/// because we sent everything as HTTP body, but it could evolve.
///
/// ## Performance
/// This implementation is far from being optimal. Between HTTP and transport layer, there exists
/// one round of serialization and deserialization to properly represent the types. It is not critical
/// to address, because MPC helpers have to handle a constant number of requests per query. Note
/// that all requests tagged with [`crate::helpers::transport::RouteId::Records`] are not routed
/// through [`RequestHandler`], so there is no penalty.
///
pub struct HelperResponse {
body: Vec<u8>,
// Empty,
// QueryCreated(QueryId),
// QueryStatus(QueryStatus),
}

impl Debug for HelperResponse {
Expand All @@ -41,6 +48,7 @@ impl Debug for HelperResponse {
}

impl HelperResponse {
/// Returns
pub fn ok() -> Self {
Self { body: Vec::new() }
}
Expand All @@ -49,14 +57,8 @@ impl HelperResponse {
self.body
}

pub fn into_owned<T: DeserializeOwned>(self) -> T {
serde_json::from_slice(&self.body).unwrap_or_else(|e| {
panic!(
"Failed to deserialize {:?} into {}: {e}",
&self.body,
type_name::<T>()
)
})
pub fn try_into_owned<T: DeserializeOwned>(self) -> Result<T, serde_json::Error> {
serde_json::from_slice(&self.body)
}
}

Expand Down
1 change: 0 additions & 1 deletion ipa-core/src/helpers/transport/in_memory/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ impl<I: TransportIdentity> InMemoryTransport<I> {
),
)
.await
// callbacks.handle(Clone::clone(&this), addr).await
}
};

Expand Down
8 changes: 5 additions & 3 deletions ipa-core/src/net/http_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ pub mod query {
pub query_id: QueryId,
}

impl From<HelperResponse> for ResponseBody {
fn from(value: HelperResponse) -> Self {
value.into_owned()
impl TryFrom<HelperResponse> for ResponseBody {
type Error = serde_json::Error;

fn try_from(value: HelperResponse) -> Result<Self, Self::Error> {
value.try_into_owned()
}
}

Expand Down
4 changes: 3 additions & 1 deletion ipa-core/src/net/server/handlers/query/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ async fn handler(
.dispatch(req.query_config, BodyStream::empty())
.await
{
Ok(resp) => Ok(Json(resp.into())),
Ok(resp) => {
Ok(Json(resp.try_into()?))
},
Err(err @ NewQuery(NewQueryError::State { .. })) => {
Err(Error::application(StatusCode::CONFLICT, err))
}
Expand Down

0 comments on commit d029c6f

Please sign in to comment.