Now instead of wrapping JsonResponse, JsonError, and JsonNotification, we can just use into().
@@ -80,6 +80,24 @@ pub enum JsonResult {
Notif(JsonNotification),
}
+impl From<JsonResponse> for JsonResult {
+ fn from(resp: JsonResponse) -> Self {
+ Self::Resp(resp)
+ }
+}
+
+impl From<JsonError> for JsonResult {
+ fn from(err: JsonError) -> Self {
+ Self::Err(err)
+impl From<JsonNotification> for JsonResult {
+ fn from(notif: JsonNotification) -> Self {
+ Self::Notif(notif)
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct JsonRequest {
pub jsonrpc: Value,
@@ -35,6 +35,14 @@ pub fn join_config_path(file: &Path) -> Result<PathBuf> {
Ok(path)
+pub fn get_config_path(arg: Option<String>, fallback: &str) -> Result<PathBuf> {
+ if arg.is_some() {
+ expand_path(&arg.unwrap())
+ } else {
+ join_config_path(&PathBuf::from(fallback))
pub fn load_keypair_to_str(path: PathBuf) -> Result<String> {
if Path::new(&path).exists() {
let key = fs::read(&path)?;