use a trait object for the server, for dynamic dispatch

This commit is contained in:
Dustin J. Mitchell
2020-11-26 10:52:28 -05:00
parent 087333a227
commit a5c06008b3
5 changed files with 36 additions and 15 deletions

View File

@@ -1,8 +1,7 @@
use crate::server::SyncServer;
use crate::api::ServerState;
use crate::types::{ClientId, HistorySegment, VersionId};
use actix_web::{error, http::StatusCode, post, web, HttpResponse, Responder, Result};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
/// Request body to add_version
#[derive(Serialize, Deserialize)]
@@ -14,7 +13,7 @@ pub(crate) struct AddVersionRequest {
#[post("/client/{client_id}/add-version/{parent_version_id}")]
pub(crate) async fn service(
data: web::Data<Arc<SyncServer>>,
data: web::Data<ServerState>,
web::Path((client_id, parent_version_id)): web::Path<(ClientId, VersionId)>,
body: web::Json<AddVersionRequest>,
) -> Result<impl Responder> {

View File

@@ -1,11 +1,10 @@
use crate::server::SyncServer;
use crate::api::ServerState;
use crate::types::{ClientId, VersionId};
use actix_web::{error, get, http::StatusCode, web, HttpResponse, Result};
use std::sync::Arc;
#[get("/client/{client_id}/get-child-version/{parent_version_id}")]
pub(crate) async fn service(
data: web::Data<Arc<SyncServer>>,
data: web::Data<ServerState>,
web::Path((client_id, parent_version_id)): web::Path<(ClientId, VersionId)>,
) -> Result<HttpResponse> {
let result = data

View File

@@ -1,2 +1,8 @@
use crate::server::SyncServer;
use std::sync::Arc;
pub(crate) mod add_version;
pub(crate) mod get_child_version;
/// The type containing a reference to the SyncServer object in the Actix state.
pub(crate) type ServerState = Arc<Box<dyn SyncServer>>;