You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/01 02:13:11 UTC
[GitHub] [arrow-rs] liyongjing commented on issue #1969: close function instead of mutable reference
liyongjing commented on issue #1969:
URL: https://github.com/apache/arrow-rs/issues/1969#issuecomment-1171850627
I call `write` multiple times, call `close` one times using static HashMap.
```rust
fn global() -> &'static Mutex<HashMap<String, Writer>> {
static INSTANCE: OnceCell<Mutex<HashMap<String, Writer>>> = OnceCell::new();
INSTANCE.get_or_init(|| Mutex::new(HashMap::new()))
}
pub fn write(path: &str, val: Vec<u8>) {
let mut g = global_channel().lock().unwrap();
let w = g.entry(path.to_string()).or_insert(Writer::new(path));
let batch = ...;
w.write(&batch);
}
pub fn close(path: &str) {
let mut g = global_channel().lock().unwrap();
if let Some(v) = g.get_mut(path) {
// *v don't copy
v.close();
}
g.remove(path);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org