Working on a library based on Neon that is an experiment to see how it performs in comparison to safe_app_nodejs.
-
safe_app_nodejs is working with FFI
-
safe_app_neon is working with Neon, which creates addons in Rust instead of C++
The current stable implementation is able to allow an app to register itself on a system, to generate an auth URI, and to open a URI on a system, as shown in this example app.
The next step in implementation, on update branch, is to allow an app to connect to the network, now that it’s able to receive an auth-granted URI.
In order to connect an app to network, I’ll need to process the URI it received back from authenticator, and this is where I need help:
If I were utilising the exposed FFI, I’d be using decode_ipc_msg, to decode the returned URI, where a respective callback is called depending on how the app was asking to connect with network.
However, in my library, I have my own function named decode_ipc_msg, that I want to return a value instead of calling a callback.
Specifically, I want an app to be connected to network and to simply return the App struct, in the case that my app has been granted authorisation, to be utilised when my app needs to call further operations on the network.
What I specifically need help with is understanding how to properly destructure the data returned from decode_msg
and what to make my return type for decode_ipc_msg
.
Right now the return type is Result<???, AppError>
.
It appears that AppError
is fine for the case of an Err
, but there are multiple possibilities for the Ok()
portion of the Result
type.
IpcMsg::Resp {
resp: IpcResp::Auth(res),
req_id,
} => {
match res {
Ok(auth_granted) => App::registered(app_id, auth_granted, move |event| {println!("Network state: {:?}", event)}),
Err(err) => Err(AppError::from(err)),
}
},
IpcMsg::Resp {
resp: IpcResp::Containers(res),
req_id,
} => {
match res {
Ok(()) => req_id,
Err(err) => AppError::from(err)
}
},
IpcMsg::Resp {
resp: IpcResp::Unregistered(res),
req_id,
} => {
match res {
Ok(bootstrap_cfg) => serialise(&bootstrap_cfg)?,
Err(err) => AppError::from(err)
}
},
IpcMsg::Resp {
resp: IpcResp::ShareMData(res),
req_id,
} => {
match res {
Ok(()) => req_id,
Err(err) => AppError::from(err),
}
}
Ok()
, based on this match tree, may be an i32
, App
, or a Vec<u8>
I must need a fresh perspective on how to more simply return a desired value from decode_msg.