Skip to content

Commit

Permalink
feat: apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
indietyp committed Nov 8, 2024
1 parent 334add2 commit 575d32b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
2 changes: 2 additions & 0 deletions libs/@local/graph/api/src/rpc/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl Error for AccountNotFoundError {
}
}

#[must_use]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, derive_more::Display, derive_more::Error)]
#[display("unable to fullfil account request")]
pub struct AccountError;
Expand Down Expand Up @@ -469,6 +470,7 @@ pub struct AccountDelegate<T> {
}

impl<T> AccountDelegate<T> {
#[must_use]
pub const fn new(inner: T) -> Self {
Self { inner }
}
Expand Down
10 changes: 9 additions & 1 deletion libs/@local/graph/api/src/rpc/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use hash_graph_types::account::AccountId;

use super::session::Account;

#[must_use]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, derive_more::Display, derive_more::Error)]
#[display("unable to authenticate user")]
pub struct AuthenticationError;
Expand Down Expand Up @@ -115,6 +116,13 @@ pub struct AuthenticationDelegate<T> {
inner: T,
}

impl<T> AuthenticationDelegate<T> {
#[must_use]
pub const fn new(inner: T) -> Self {
Self { inner }
}
}

impl<T, C> SubsystemDelegate<C> for AuthenticationDelegate<T>
where
T: AuthenticationSystem<authenticate(..): Send, ExecutionScope: Send> + Send,
Expand Down Expand Up @@ -160,7 +168,7 @@ pub struct AuthenticationClient<S, C> {

impl<S, C> AuthenticationClient<S, C> {
#[must_use]
pub fn new() -> Self {
pub const fn new() -> Self {
Self {
_service: PhantomData,
_codec: PhantomData,
Expand Down
18 changes: 18 additions & 0 deletions libs/@local/graph/api/src/rpc/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use harpc_types::response_kind::ResponseKind;

use super::session::Account;

#[must_use]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, derive_more::Display, derive_more::Error)]
#[display("unable to fullfil ping request")]
pub struct EchoError;
Expand Down Expand Up @@ -108,6 +109,7 @@ pub struct EchoDelegate<T> {
}

impl<T> EchoDelegate<T> {
#[must_use]
pub const fn new(inner: T) -> Self {
Self { inner }
}
Expand Down Expand Up @@ -155,6 +157,22 @@ pub struct EchoClient<S, C> {
_codec: PhantomData<fn() -> *const C>,
}

impl<S, C> EchoClient<S, C> {
#[must_use]
pub const fn new() -> Self {
Self {
_service: PhantomData,
_codec: PhantomData,
}
}
}

impl<S, C> Default for EchoClient<S, C> {
fn default() -> Self {
Self::new()
}
}

impl<S, C> EchoSystem for EchoClient<S, C>
where
S: harpc_client::connection::ConnectionService<C>,
Expand Down
27 changes: 21 additions & 6 deletions libs/@local/harpc/server/examples/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use core::{fmt::Debug, marker::PhantomData};
use std::time::Instant;

use error_stack::{Report, ResultExt as _};
use frunk::HList;; Client, ClientConfig,
use frunk::HList;
use harpc_client::{
Client, ClientConfig,
connection::{Connection, ConnectionCodec, ConnectionService},
utils::invoke_call_discrete,
};
Expand Down Expand Up @@ -118,6 +120,7 @@ impl Procedure for CreateAccount {
const ID: <Self::Subsystem as Subsystem>::ProcedureId = AccountProcedureId::CreateAccount;
}

#[must_use]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, derive_more::Display, derive_more::Error)]
#[display("unable to fullfil account request")]
pub struct AccountError;
Expand All @@ -138,7 +141,8 @@ struct AccountSystemImpl<S> {
}

impl<S> AccountSystemImpl<S> {
fn new() -> Self {
#[must_use]
const fn new() -> Self {
Self {
_scope: PhantomData,
}
Expand Down Expand Up @@ -167,14 +171,20 @@ struct AccountSystemClient<S, C> {
}

impl<S, C> AccountSystemClient<S, C> {
fn new() -> Self {
const fn new() -> Self {
Self {
_service: PhantomData,
_codec: PhantomData,
}
}
}

impl<S, C> Default for AccountSystemClient<S, C> {
fn default() -> Self {
Self::new()
}
}

impl<S, C> AccountSystem for AccountSystemClient<S, C>
where
S: ConnectionService<C>,
Expand All @@ -198,6 +208,13 @@ struct AccountServerDelegate<T> {
subsystem: T,
}

impl<T> AccountServerDelegate<T> {
#[must_use]
const fn new(subsystem: T) -> Self {
Self { subsystem }
}
}

impl<T, C> SubsystemDelegate<C> for AccountServerDelegate<T>
where
T: AccountSystem<create_account(..): Send, ExecutionScope: Send> + Send + Sync,
Expand Down Expand Up @@ -244,9 +261,7 @@ async fn server() {
.layer(HandleReportLayer::new())
.layer(HandleBodyReportLayer::new())
})
.register(AccountServerDelegate {
subsystem: AccountSystemImpl::new(),
});
.register(AccountServerDelegate::new(AccountSystemImpl::new()));

let task = router.background_task(server.events());
tokio::spawn(task.into_future());
Expand Down

0 comments on commit 575d32b

Please sign in to comment.