Skip to content

Commit

Permalink
Revert "Try to use generics and type annotations."
Browse files Browse the repository at this point in the history
This reverts commit 7112803.
  • Loading branch information
G8XSU committed Nov 21, 2024
1 parent ab55480 commit 1349652
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
5 changes: 3 additions & 2 deletions rust/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use crate::vss_service::VssService;
use api::auth::NoopAuthorizer;
use api::auth::{Authorizer, NoopAuthorizer};
use api::kv_store::KvStore;
use impls::postgres_store::PostgresBackendImpl;
use std::sync::Arc;

Expand Down Expand Up @@ -58,7 +59,7 @@ fn main() {
match res {
Ok((stream, _)) => {
let io_stream = TokioIo::new(stream);
let vss_service = VssService::new(Arc::clone(&store), Arc::clone(&authorizer));
let vss_service = VssService::new(Arc::clone(&store) as Arc<dyn KvStore>, Arc::clone(&authorizer) as Arc<dyn Authorizer>);
runtime.spawn(async move {
if let Err(err) = http1::Builder::new().serve_connection(io_stream, vss_service).await {
eprintln!("Failed to serve connection: {}", err);
Expand Down
49 changes: 18 additions & 31 deletions rust/server/src/vss_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,18 @@ use std::pin::Pin;
use std::sync::Arc;

#[derive(Clone)]
pub struct VssService<K, A>
where
K: KvStore,
A: Authorizer,
{
store: Arc<K>,
authorizer: Arc<A>,
pub struct VssService {
store: Arc<dyn KvStore>,
authorizer: Arc<dyn Authorizer>,
}

impl<K, A> VssService<K, A>
where
K: KvStore,
A: Authorizer,
{
pub(crate) fn new(store: Arc<K>, authorizer: Arc<A>) -> Self {
impl VssService {
pub(crate) fn new(store: Arc<dyn KvStore>, authorizer: Arc<dyn Authorizer>) -> Self {
Self { store, authorizer }
}
}

impl<K, A> Service<Request<Incoming>> for VssService<K, A>
where
K: KvStore + 'static,
A: Authorizer + 'static,
{
impl Service<Request<Incoming>> for VssService {
type Response = Response<Full<Bytes>>;
type Error = hyper::Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
Expand Down Expand Up @@ -77,36 +65,35 @@ where
}
}

async fn handle_get_object_request<K: KvStore>(
store: Arc<K>, user_token: String, request: GetObjectRequest,
async fn handle_get_object_request(
store: Arc<dyn KvStore>, user_token: String, request: GetObjectRequest,
) -> Result<GetObjectResponse, VssError> {
store.get(user_token, request).await
}
async fn handle_put_object_request<K: KvStore>(
store: Arc<K>, user_token: String, request: PutObjectRequest,
async fn handle_put_object_request(
store: Arc<dyn KvStore>, user_token: String, request: PutObjectRequest,
) -> Result<PutObjectResponse, VssError> {
store.put(user_token, request).await
}
async fn handle_delete_object_request<K: KvStore>(
store: Arc<K>, user_token: String, request: DeleteObjectRequest,
async fn handle_delete_object_request(
store: Arc<dyn KvStore>, user_token: String, request: DeleteObjectRequest,
) -> Result<DeleteObjectResponse, VssError> {
store.delete(user_token, request).await
}
async fn handle_list_object_request<K: KvStore>(
store: Arc<K>, user_token: String, request: ListKeyVersionsRequest,
async fn handle_list_object_request(
store: Arc<dyn KvStore>, user_token: String, request: ListKeyVersionsRequest,
) -> Result<ListKeyVersionsResponse, VssError> {
store.list_key_versions(user_token, request).await
}
async fn handle_request<
T: Message + Default,
R: Message,
F: FnOnce(Arc<K>, String, T) -> Fut + Send,
F: FnOnce(Arc<dyn KvStore>, String, T) -> Fut + Send + 'static,
Fut: Future<Output = Result<R, VssError>> + Send,
K: KvStore + 'static,
A: Authorizer + 'static,
>(
store: Arc<K>, authorizer: Arc<A>, request: Request<Incoming>, handler: F,
) -> Result<<VssService<K, A> as Service<Request<Incoming>>>::Response, hyper::Error> {
store: Arc<dyn KvStore>, authorizer: Arc<dyn Authorizer>, request: Request<Incoming>,
handler: F,
) -> Result<<VssService as Service<Request<Incoming>>>::Response, hyper::Error> {
let (parts, body) = request.into_parts();
let headers_map = parts
.headers
Expand Down

0 comments on commit 1349652

Please sign in to comment.