44//! The Vmgs worker will send messages to the Vmgs dispatch, allowing
55//! tasks to queue for the dispatcher to handle synchronously
66
7+ use crate :: broker:: VmgsBrokerError ;
78use crate :: broker:: VmgsBrokerRpc ;
89use inspect:: Inspect ;
9- use mesh_channel:: rpc:: RpcError ;
10- use mesh_channel:: rpc:: RpcSend ;
10+ use mesh:: MeshPayload ;
11+ use mesh:: rpc:: RpcError ;
12+ use mesh:: rpc:: RpcSend ;
1113use thiserror:: Error ;
1214use tracing:: instrument;
1315use vmgs:: VmgsFileInfo ;
@@ -19,14 +21,22 @@ use vmgs_format::FileId;
1921pub enum VmgsClientError {
2022 /// VMGS broker is offline
2123 #[ error( "broker is offline" ) ]
22- BrokerOffline ( #[ from ] RpcError ) ,
24+ BrokerOffline ( #[ source ] RpcError ) ,
2325 /// VMGS error
2426 #[ error( "vmgs error" ) ]
25- Vmgs ( #[ from ] vmgs :: Error ) ,
27+ Vmgs ( #[ source ] VmgsBrokerError ) ,
2628}
2729
28- impl From < RpcError < vmgs:: Error > > for VmgsClientError {
29- fn from ( value : RpcError < vmgs:: Error > ) -> Self {
30+ impl From < RpcError > for VmgsClientError {
31+ fn from ( value : RpcError ) -> Self {
32+ match value {
33+ RpcError :: Channel ( e) => VmgsClientError :: BrokerOffline ( RpcError :: Channel ( e) ) ,
34+ }
35+ }
36+ }
37+
38+ impl From < RpcError < VmgsBrokerError > > for VmgsClientError {
39+ fn from ( value : RpcError < VmgsBrokerError > ) -> Self {
3040 match value {
3141 RpcError :: Call ( e) => VmgsClientError :: Vmgs ( e) ,
3242 RpcError :: Channel ( e) => VmgsClientError :: BrokerOffline ( RpcError :: Channel ( e) ) ,
@@ -35,10 +45,10 @@ impl From<RpcError<vmgs::Error>> for VmgsClientError {
3545}
3646
3747/// Client to interact with a backend-agnostic VMGS instance.
38- #[ derive( Clone , Inspect ) ]
48+ #[ derive( Clone , Inspect , MeshPayload ) ]
3949pub struct VmgsClient {
4050 #[ inspect( flatten, send = "VmgsBrokerRpc::Inspect" ) ]
41- pub ( crate ) control : mesh_channel :: Sender < VmgsBrokerRpc > ,
51+ pub ( crate ) control : mesh :: Sender < VmgsBrokerRpc > ,
4252}
4353
4454impl VmgsClient {
@@ -47,7 +57,7 @@ impl VmgsClient {
4757 pub async fn get_file_info ( & self , file_id : FileId ) -> Result < VmgsFileInfo , VmgsClientError > {
4858 let res = self
4959 . control
50- . call_failable ( VmgsBrokerRpc :: GetFileInfo , file_id)
60+ . call_failable ( VmgsBrokerRpc :: GetFileInfo , file_id. into ( ) )
5161 . await ?;
5262
5363 Ok ( res)
@@ -58,7 +68,7 @@ impl VmgsClient {
5868 pub async fn read_file ( & self , file_id : FileId ) -> Result < Vec < u8 > , VmgsClientError > {
5969 let res = self
6070 . control
61- . call_failable ( VmgsBrokerRpc :: ReadFile , file_id)
71+ . call_failable ( VmgsBrokerRpc :: ReadFile , file_id. into ( ) )
6272 . await ?;
6373
6474 Ok ( res)
@@ -71,7 +81,7 @@ impl VmgsClient {
7181 #[ instrument( skip_all, fields( file_id) ) ]
7282 pub async fn write_file ( & self , file_id : FileId , buf : Vec < u8 > ) -> Result < ( ) , VmgsClientError > {
7383 self . control
74- . call_failable ( VmgsBrokerRpc :: WriteFile , ( file_id, buf) )
84+ . call_failable ( VmgsBrokerRpc :: WriteFile , ( file_id. into ( ) , buf) )
7585 . await ?;
7686
7787 Ok ( ( ) )
@@ -88,7 +98,7 @@ impl VmgsClient {
8898 buf : Vec < u8 > ,
8999 ) -> Result < ( ) , VmgsClientError > {
90100 self . control
91- . call_failable ( VmgsBrokerRpc :: WriteFileEncrypted , ( file_id, buf) )
101+ . call_failable ( VmgsBrokerRpc :: WriteFileEncrypted , ( file_id. into ( ) , buf) )
92102 . await ?;
93103
94104 Ok ( ( ) )
0 commit comments