From b8578a89a4b1cfc60d403dad41ff126de77870ef Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 17 Aug 2023 00:04:37 +0200 Subject: [PATCH] fix: inaccessible fields, pub(crate) constructor --- src/buffer/controller.rs | 10 ++++++++++ src/buffer/worker.rs | 10 +++++----- src/client.rs | 8 ++++---- src/cursor/controller.rs | 10 ++++++++++ src/cursor/worker.rs | 10 +++++----- src/instance.rs | 2 -- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/buffer/controller.rs b/src/buffer/controller.rs index 73e967e..bf861e7 100644 --- a/src/buffer/controller.rs +++ b/src/buffer/controller.rs @@ -13,6 +13,16 @@ pub struct BufferController { stream: Mutex>, } +impl BufferController { + pub(crate) fn new( + content: watch::Receiver, + operations: mpsc::Sender, + stream: Mutex>, + ) -> Self { + BufferController { content, operations, stream } + } +} + #[async_trait] impl OperationFactory for BufferController { fn content(&self) -> String { diff --git a/src/buffer/worker.rs b/src/buffer/worker.rs index 43bb008..99e673e 100644 --- a/src/buffer/worker.rs +++ b/src/buffer/worker.rs @@ -51,11 +51,11 @@ impl ControllerWorker for BufferControllerWorker { type Rx = Streaming; fn subscribe(&self) -> BufferController { - BufferController { - content: self.receiver.clone(), - operations: self.sender.clone(), - stream: Mutex::new(self.stream.subscribe()), - } + BufferController::new( + self.receiver.clone(), + self.sender.clone(), + Mutex::new(self.stream.subscribe()), + ) } async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) { diff --git a/src/client.rs b/src/client.rs index 9691ee2..453c944 100644 --- a/src/client.rs +++ b/src/client.rs @@ -38,11 +38,11 @@ impl CodempClient { } pub fn get_cursor(&self) -> Option> { - Some(self.workspace?.cursor.clone()) + Some(self.workspace.as_ref()?.cursor.clone()) } pub fn get_buffer(&self, path: &str) -> Option> { - self.workspace?.buffers.get(path).cloned() + self.workspace.as_ref()?.buffers.get(path).cloned() } pub async fn join(&mut self, _session: &str) -> Result, CodempError> { @@ -72,7 +72,7 @@ impl CodempClient { } pub async fn create(&mut self, path: &str, content: Option<&str>) -> Result<(), CodempError> { - if let Some(workspace) = &self.workspace { + if let Some(_workspace) = &self.workspace { self.client.buffer .create(BufferPayload { user: self.id.clone(), @@ -86,7 +86,7 @@ impl CodempClient { } } - pub async fn attach(&mut self, path: &str, content: Option<&str>) -> Result, CodempError> { + pub async fn attach(&mut self, path: &str) -> Result, CodempError> { if let Some(workspace) = &mut self.workspace { let mut client = self.client.buffer.clone(); let req = BufferPayload { diff --git a/src/cursor/controller.rs b/src/cursor/controller.rs index 7e879a7..d553314 100644 --- a/src/cursor/controller.rs +++ b/src/cursor/controller.rs @@ -9,6 +9,16 @@ pub struct CursorController { stream: Mutex>, } +impl CursorController { + pub(crate) fn new( + uid: String, + op: mpsc::Sender, + stream: Mutex> + ) -> Self { + CursorController { uid, op, stream } + } +} + #[async_trait] impl Controller for CursorController { type Input = CursorPosition; diff --git a/src/cursor/worker.rs b/src/cursor/worker.rs index 42fa694..c847fcd 100644 --- a/src/cursor/worker.rs +++ b/src/cursor/worker.rs @@ -34,11 +34,11 @@ impl ControllerWorker for CursorControllerWorker { type Rx = Streaming; fn subscribe(&self) -> CursorController { - CursorController { - uid: self.uid.clone(), - op: self.producer.clone(), - stream: Mutex::new(self.channel.subscribe()), - } + CursorController::new( + self.uid.clone(), + self.producer.clone(), + Mutex::new(self.channel.subscribe()) + ) } async fn work(mut self, mut tx: Self::Tx, mut rx: Self::Rx) { diff --git a/src/instance.rs b/src/instance.rs index 1421d29..0feec6a 100644 --- a/src/instance.rs +++ b/src/instance.rs @@ -10,8 +10,6 @@ use crate::{ use tokio::runtime::Runtime; -const CODEMP_DEFAULT_HOST : &str = "http://alemi.dev:50051"; - lazy_static::lazy_static! { static ref RUNTIME : Runtime = Runtime::new().expect("could not create tokio runtime"); static ref INSTANCE : Instance = Instance::default();