mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
Split SCS thrift service trait from the main implementation
Summary: `SourceControlServiceImpl` has duplicate methods for each of the thrift methods: one base method that implements the functionality, and one trait method that delegates to the base method. This could be confusing if we fail to resolve the correct method. Instead, split the two out to separate structs by making the thrift server a wrapper around the base implementation that only contains the delegation methods. Reviewed By: mitrandir77 Differential Revision: D18745443 fbshipit-source-id: 5acdad2f1f66562ecf71f85ebf2b83d15f0edc9a
This commit is contained in:
parent
d275d77a8e
commit
67913196ed
@ -155,7 +155,11 @@ fn main(fb: FacebookInit) -> Result<(), Error> {
|
||||
);
|
||||
let service = {
|
||||
move |proto| {
|
||||
make_SourceControlService_server(proto, source_control_server.clone(), fb303.clone())
|
||||
make_SourceControlService_server(
|
||||
proto,
|
||||
source_control_server.thrift_server(),
|
||||
fb303.clone(),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -30,13 +30,15 @@ use crate::from_request::FromRequest;
|
||||
use crate::specifiers::SpecifierExt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SourceControlServiceImpl {
|
||||
pub(crate) struct SourceControlServiceImpl {
|
||||
pub(crate) fb: FacebookInit,
|
||||
pub(crate) mononoke: Arc<Mononoke>,
|
||||
pub(crate) logger: Logger,
|
||||
pub(crate) scuba_builder: ScubaSampleBuilder,
|
||||
}
|
||||
|
||||
pub(crate) struct SourceControlServiceThriftImpl(SourceControlServiceImpl);
|
||||
|
||||
impl SourceControlServiceImpl {
|
||||
pub fn new(
|
||||
fb: FacebookInit,
|
||||
@ -52,6 +54,10 @@ impl SourceControlServiceImpl {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn thrift_server(&self) -> SourceControlServiceThriftImpl {
|
||||
SourceControlServiceThriftImpl(self.clone())
|
||||
}
|
||||
|
||||
pub(crate) fn create_ctx(&self, specifier: Option<&dyn SpecifierExt>) -> CoreContext {
|
||||
let mut scuba = self.scuba_builder.clone();
|
||||
scuba.add_common_server_data().add("type", "thrift");
|
||||
@ -214,13 +220,13 @@ macro_rules! impl_thrift_methods {
|
||||
'implementation: 'async_trait,
|
||||
Self: Sync + 'async_trait,
|
||||
{
|
||||
Box::pin(self.$method_name( $( $param_name ),* ))
|
||||
Box::pin((self.0).$method_name( $( $param_name ),* ))
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
|
||||
impl SourceControlService for SourceControlServiceImpl {
|
||||
impl SourceControlService for SourceControlServiceThriftImpl {
|
||||
impl_thrift_methods! {
|
||||
async fn list_repos(
|
||||
params: thrift::ListReposParams,
|
||||
|
Loading…
Reference in New Issue
Block a user