diff --git a/src/api/config.rs b/src/api/config.rs index 58cfd2f..23dc7ef 100644 --- a/src/api/config.rs +++ b/src/api/config.rs @@ -30,10 +30,10 @@ pub struct Config { impl Config { /// construct a new Config object, with given username and password - pub fn new(username: String, password: String) -> Self { + pub fn new(username: impl ToString, password: impl ToString) -> Self { Self { - username, - password, + username: username.to_string(), + password: password.to_string(), host: None, port: None, tls: None, diff --git a/src/ffi/js/workspace.rs b/src/ffi/js/workspace.rs index a470c2e..8437a82 100644 --- a/src/ffi/js/workspace.rs +++ b/src/ffi/js/workspace.rs @@ -16,6 +16,11 @@ impl Workspace { self.filetree(filter, strict) } + #[napi(js_name = "user_list")] + pub fn js_user_list(&self) -> Vec { + self.user_list() + } + #[napi(js_name = "cursor")] pub fn js_cursor(&self) -> CursorController { self.cursor() diff --git a/src/ffi/lua/workspace.rs b/src/ffi/lua/workspace.rs index 5ce4bd2..caed60b 100644 --- a/src/ffi/lua/workspace.rs +++ b/src/ffi/lua/workspace.rs @@ -41,6 +41,10 @@ impl LuaUserData for CodempWorkspace { methods.add_method("filetree", |_, this, (filter, strict,):(Option, Option,)| Ok(this.filetree(filter.as_deref(), strict.unwrap_or(false))) ); + + methods.add_method("user_list", |_, this, ()| + Ok(this.user_list()) + ); } fn add_fields>(fields: &mut F) { diff --git a/src/ffi/python/workspace.rs b/src/ffi/python/workspace.rs index 1a10f4d..79574b8 100644 --- a/src/ffi/python/workspace.rs +++ b/src/ffi/python/workspace.rs @@ -86,4 +86,9 @@ impl Workspace { fn pyfiletree(&self, filter: Option<&str>, strict: bool) -> Vec { self.filetree(filter, strict) } + + #[pyo3(name = "user_list")] + fn pyuser_list(&self) -> Vec { + self.user_list() + } } diff --git a/src/workspace.rs b/src/workspace.rs index 7c11461..d278ccd 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -285,6 +285,15 @@ impl Workspace { .collect() } + /// Get all names of users currently in this workspace + pub fn user_list(&self) -> Vec { + self.0 + .users + .iter() + .map(|elem| elem.value().name.clone()) + .collect() + } + /// Get the filetree as it is currently cached. /// A filter may be applied, and it may be strict (equality check) or not (starts_with check). // #[cfg_attr(feature = "js", napi)] // https://github.com/napi-rs/napi-rs/issues/1120