Fix compile errors and add api client
Signed-off-by: trivernis <trivernis@protonmail.com>pull/4/head
parent
ace0d78aea
commit
4ca755c17c
@ -0,0 +1,9 @@
|
||||
use thiserror::Error;
|
||||
|
||||
pub type ApiResult<T> = Result<T, ApiError>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ApiError {
|
||||
#[error(transparent)]
|
||||
IPC(#[from] rmp_ipc::error::Error)
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
pub mod error;
|
||||
|
||||
use rmp_ipc::ipc::context::Context;
|
||||
use rmp_ipc::IPCBuilder;
|
||||
use crate::client_api::error::ApiResult;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApiClient {
|
||||
ctx: Context,
|
||||
}
|
||||
|
||||
impl ApiClient {
|
||||
/// Creates a new client from an existing ipc context
|
||||
pub fn new(ctx: Context) -> Self {
|
||||
Self {ctx}
|
||||
}
|
||||
|
||||
/// Connects to the ipc Socket
|
||||
pub async fn connect(address: &str) -> ApiResult<Self> {
|
||||
let ctx = IPCBuilder::new().address(address).build_client().await?;
|
||||
|
||||
Ok(Self::new(ctx))
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
pub mod types;
|
||||
|
||||
#[cfg(feature = "client-api")]
|
||||
pub mod client_api;
|
||||
|
||||
#[cfg(feature = "tauri-plugin")]
|
||||
pub mod tauri_plugin;
|
||||
|
Loading…
Reference in New Issue