From 1cc03838eb20c3de54e819a7f8a6e14c92324990 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 17 Aug 2023 04:36:24 +0200 Subject: [PATCH] feat: return controllers, add attach --- src/instance.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/instance.rs b/src/instance.rs index 8d316b7..54c49ee 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -4,7 +4,7 @@ use tokio::sync::Mutex; use crate::{ buffer::controller::BufferController, - errors::Error, client::Client, cursor::controller::CursorController, + errors::Error, client::Client, cursor::controller::CursorController, Controller, }; @@ -33,16 +33,14 @@ impl Instance { Ok(()) } - pub async fn join(&self, session: &str) -> Result<(), Error> { + pub async fn join(&self, session: &str) -> Result, Error> { self.client .lock() .await .as_mut() .ok_or(Error::InvalidState { msg: "connect first".into() })? .join(session) - .await?; - - Ok(()) + .await } pub async fn create(&self, path: &str, content: Option<&str>) -> Result<(), Error> { @@ -52,9 +50,17 @@ impl Instance { .as_mut() .ok_or(Error::InvalidState { msg: "connect first".into() })? .create(path, content) - .await?; + .await + } - Ok(()) + pub async fn attach(&self, path: &str) -> Result, Error> { + self.client + .lock() + .await + .as_mut() + .ok_or(Error::InvalidState { msg: "connect first".into() })? + .attach(path) + .await } pub async fn get_cursor(&self) -> Result, Error> {