fix: uuid was copy, string is not

This commit is contained in:
əlemi 2024-09-06 00:12:31 +02:00
parent 917a6b96c2
commit fb5bb51e65
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 10 additions and 9 deletions

View file

@ -92,10 +92,10 @@ pub extern "system" fn Java_mp_code_CursorController_send<'local>(
let user = if user.is_null() { let user = if user.is_null() {
None None
} else { } else {
let user: String = env.get_string(&user) Some(env.get_string(&user)
.map(|u| u.into()) .map(|u| u.into())
.jexcept(&mut env); .jexcept(&mut env)
Some(uuid::Uuid::parse_str(&user).jexcept(&mut env)) )
}; };
let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::cursor::Controller)) }; let controller = unsafe { Box::leak(Box::from_raw(self_ptr as *mut crate::cursor::Controller)) };

View file

@ -35,7 +35,7 @@ impl BufferController {
#[napi(js_name = "get_path")] #[napi(js_name = "get_path")]
pub fn js_path(&self) -> napi::Result<&str> { pub fn js_path(&self) -> napi::Result<&str> {
Ok(&self.path()) Ok(self.path())
} }
#[napi(js_name = "poll")] #[napi(js_name = "poll")]
@ -50,7 +50,7 @@ impl BufferController {
#[napi(js_name = "recv")] #[napi(js_name = "recv")]
pub async fn js_recv(&self) -> napi::Result<TextChange> { pub async fn js_recv(&self) -> napi::Result<TextChange> {
Ok(self.recv().await?.into()) Ok(self.recv().await?)
} }
#[napi(js_name = "send")] #[napi(js_name = "send")]

View file

@ -22,7 +22,7 @@ impl From<JsCursor> for crate::api::Cursor {
start : (value.start_row, value.start_col), start : (value.start_row, value.start_col),
end: (value.end_row, value.end_col), end: (value.end_row, value.end_col),
buffer: value.buffer, 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")] #[napi(js_name= "try_recv")]
pub async fn js_try_recv(&self) -> napi::Result<Option<JsCursor>> { pub async fn js_try_recv(&self) -> napi::Result<Option<JsCursor>> {
Ok(self.try_recv().await? Ok(self.try_recv().await?
.map(|x| JsCursor::from(x))) .map(JsCursor::from))
} }
#[napi(js_name= "recv")] #[napi(js_name= "recv")]

View file

@ -52,6 +52,7 @@ fn tokio() -> &'static tokio::runtime::Runtime {
} }
// TODO cannot do Box<dyn IntoLuaMulti> ?? maybe its temporary because im using betas // TODO cannot do Box<dyn IntoLuaMulti> ?? maybe its temporary because im using betas
#[allow(unused)] // TODO pass callback args!
enum CallbackArg { enum CallbackArg {
CursorController(CodempCursorController), CursorController(CodempCursorController),
BufferController(CodempBufferController), BufferController(CodempBufferController),
@ -351,7 +352,7 @@ impl LuaUserData for Cursor {
} }
fn add_fields<'lua, F: LuaUserDataFields<'lua, Self>>(fields: &mut F) { 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("buffer", |_, this| Ok(this.buffer.clone()));
fields.add_field_method_get("start", |_, this| Ok(RowCol::from(this.start))); fields.add_field_method_get("start", |_, this| Ok(RowCol::from(this.start)));
fields.add_field_method_get("finish", |_, this| Ok(RowCol::from(this.end))); fields.add_field_method_get("finish", |_, this| Ok(RowCol::from(this.end)));

View file

@ -160,6 +160,6 @@ impl Cursor {
#[getter(user)] #[getter(user)]
fn pyuser(&self) -> Option<String> { fn pyuser(&self) -> Option<String> {
self.user.map(|user| user.to_string()) self.user.clone()
} }
} }