-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: change component trait to component client trait and return re…
…sult instead of value
- Loading branch information
1 parent
a7477f1
commit 8df3617
Showing
5 changed files
with
50 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
use async_trait::async_trait; | ||
use starknet_mempool_infra::component_client::ClientResult; | ||
|
||
pub(crate) type ValueA = u32; | ||
pub(crate) type ValueB = u8; | ||
|
||
pub(crate) type ResultA = ClientResult<ValueA>; | ||
pub(crate) type ResultB = ClientResult<ValueB>; | ||
|
||
// TODO(Tsabary): add more messages / functions to the components. | ||
|
||
#[async_trait] | ||
pub(crate) trait ComponentATrait: Send + Sync { | ||
async fn a_get_value(&self) -> ValueA; | ||
#[allow(dead_code)] // Used in integration tests, which are compiled as part of a different crate. | ||
pub(crate) trait ComponentAClientTrait: Send + Sync { | ||
async fn a_get_value(&self) -> ResultA; | ||
} | ||
|
||
#[async_trait] | ||
pub(crate) trait ComponentBTrait: Send + Sync { | ||
async fn b_get_value(&self) -> ValueB; | ||
pub(crate) trait ComponentBClientTrait: Send + Sync { | ||
async fn b_get_value(&self) -> ResultB; | ||
} | ||
|
||
pub(crate) struct ComponentA { | ||
b: Box<dyn ComponentBTrait>, | ||
} | ||
|
||
#[async_trait] | ||
impl ComponentATrait for ComponentA { | ||
async fn a_get_value(&self) -> ValueA { | ||
let b_value = self.b.b_get_value().await; | ||
b_value.into() | ||
} | ||
b: Box<dyn ComponentBClientTrait>, | ||
} | ||
|
||
impl ComponentA { | ||
pub fn new(b: Box<dyn ComponentBTrait>) -> Self { | ||
pub fn new(b: Box<dyn ComponentBClientTrait>) -> Self { | ||
Self { b } | ||
} | ||
|
||
pub async fn a_get_value(&self) -> ValueA { | ||
let b_value = self.b.b_get_value().await.unwrap(); | ||
b_value.into() | ||
} | ||
} | ||
|
||
pub(crate) struct ComponentB { | ||
value: ValueB, | ||
_a: Box<dyn ComponentATrait>, | ||
} | ||
|
||
#[async_trait] | ||
impl ComponentBTrait for ComponentB { | ||
async fn b_get_value(&self) -> ValueB { | ||
self.value | ||
} | ||
_a: Box<dyn ComponentAClientTrait>, | ||
} | ||
|
||
impl ComponentB { | ||
pub fn new(value: ValueB, a: Box<dyn ComponentATrait>) -> Self { | ||
pub fn new(value: ValueB, a: Box<dyn ComponentAClientTrait>) -> Self { | ||
Self { value, _a: a } | ||
} | ||
|
||
pub fn b_get_value(&self) -> ValueB { | ||
self.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters