From fb5bb51e65712393b20db88dc7a966d8482272d8 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 6 Sep 2024 00:12:31 +0200 Subject: [PATCH] fix: uuid was copy, string is not --- src/ffi/java/cursor.rs | 6 +++--- src/ffi/js/buffer.rs | 4 ++-- src/ffi/js/cursor.rs | 4 ++-- src/ffi/lua.rs | 3 ++- src/ffi/python/controllers.rs | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ffi/java/cursor.rs b/src/ffi/java/cursor.rs index 355f7c5..2472407 100644 --- a/src/ffi/java/cursor.rs +++ b/src/ffi/java/cursor.rs @@ -92,10 +92,10 @@ pub extern "system" fn Java_mp_code_CursorController_send<'local>( let user = if user.is_null() { None } else { - let user: String = env.get_string(&user) + Some(env.get_string(&user) .map(|u| u.into()) - .jexcept(&mut env); - Some(uuid::Uuid::parse_str(&user).jexcept(&mut env)) + .jexcept(&mut env) + ) }; let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::cursor::Controller)) }; diff --git a/src/ffi/js/buffer.rs b/src/ffi/js/buffer.rs index 7d19a5a..583370f 100644 --- a/src/ffi/js/buffer.rs +++ b/src/ffi/js/buffer.rs @@ -35,7 +35,7 @@ impl BufferController { #[napi(js_name = "get_path")] pub fn js_path(&self) -> napi::Result<&str> { - Ok(&self.path()) + Ok(self.path()) } #[napi(js_name = "poll")] @@ -50,7 +50,7 @@ impl BufferController { #[napi(js_name = "recv")] pub async fn js_recv(&self) -> napi::Result { - Ok(self.recv().await?.into()) + Ok(self.recv().await?) } #[napi(js_name = "send")] diff --git a/src/ffi/js/cursor.rs b/src/ffi/js/cursor.rs index 1f1065c..b02f9f2 100644 --- a/src/ffi/js/cursor.rs +++ b/src/ffi/js/cursor.rs @@ -22,7 +22,7 @@ impl From for crate::api::Cursor { start : (value.start_row, value.start_col), end: (value.end_row, value.end_col), buffer: value.buffer, - user: value.user.map(|x| uuid::Uuid::parse_str(&x).expect("invalid uuid")), + user: value.user, } } } @@ -73,7 +73,7 @@ impl CursorController { #[napi(js_name= "try_recv")] pub async fn js_try_recv(&self) -> napi::Result> { Ok(self.try_recv().await? - .map(|x| JsCursor::from(x))) + .map(JsCursor::from)) } #[napi(js_name= "recv")] diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index 96d78a9..4247bf5 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -52,6 +52,7 @@ fn tokio() -> &'static tokio::runtime::Runtime { } // TODO cannot do Box ?? maybe its temporary because im using betas +#[allow(unused)] // TODO pass callback args! enum CallbackArg { CursorController(CodempCursorController), BufferController(CodempBufferController), @@ -351,7 +352,7 @@ impl LuaUserData for Cursor { } fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) { - fields.add_field_method_get("user", |_, this| Ok(this.user.map(|x| x.to_string()))); + fields.add_field_method_get("user", |_, this| Ok(this.user.clone())); fields.add_field_method_get("buffer", |_, this| Ok(this.buffer.clone())); fields.add_field_method_get("start", |_, this| Ok(RowCol::from(this.start))); fields.add_field_method_get("finish", |_, this| Ok(RowCol::from(this.end))); diff --git a/src/ffi/python/controllers.rs b/src/ffi/python/controllers.rs index c9cd6e1..08c09ce 100644 --- a/src/ffi/python/controllers.rs +++ b/src/ffi/python/controllers.rs @@ -160,6 +160,6 @@ impl Cursor { #[getter(user)] fn pyuser(&self) -> Option { - self.user.map(|user| user.to_string()) + self.user.clone() } }