helix icon indicating copy to clipboard operation
helix copied to clipboard

refactor: tokio::fs instead of std::fs, idiomatic error handling

Open krabodyan opened this issue 9 months ago • 2 comments

  • Standardized operations to use the existing alias use tokio::fs instead of mixing tokio::fs, fs, and std::fs. https://github.com/helix-editor/helix/blob/2bd7452fe0309e273d06280d15caad6943034377/helix-view/src/document.rs#L989
  • Refactored error handling to use if let Err(e) instead of map_err(...log::error!) for better readability and idiomatic Rust style.

krabodyan avatar May 28 '25 13:05 krabodyan

If I understand the tokio::fs stuff correctly, calling any function there is equivalent to calling tokio::task::spawn_blocking and then using std::fs. Since we don't await any messages or otherwise require async in this function, it's probably lower overhead to call tokio::task::spawn_blocking directly and use std::fs within.

the-mikedavis avatar Jun 09 '25 20:06 the-mikedavis

Yes, and spawn_blocking in rust is costly, given that there is a lock and stuff. But I guess we can go with developer ergonomics and code readability here instead.

pickfire avatar Jun 10 '25 13:06 pickfire