Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code instead of Box<dyn Error> #5

Open
iceghost opened this issue Mar 30, 2024 · 1 comment
Open

Error code instead of Box<dyn Error> #5

iceghost opened this issue Mar 30, 2024 · 1 comment

Comments

@iceghost
Copy link

iceghost commented Mar 30, 2024

I noticed some functions return Box<dyn Error>, when they can just return the error code. Is this intentional?

/// Start the handle with the given callback, which will watch the specified path for changes.
///
/// Note: Currently the only supported flag is RECURSIVE and only on OSX and Windows.
pub fn start<CB: Into<FsEventCB<'static>>>(
&mut self,
path: &str,
flags: FsEventFlags,
cb: CB,
) -> Result<(), Box<dyn std::error::Error>> {
let path = CString::new(path)?;
// uv_cb is either Some(fs_event_cb) or None
let cb = cb.into();
let uv_cb = use_c_callback!(uv_fs_event_cb, cb);
// cb is either Some(closure) or None - it is saved into data
let dataptr = crate::Handle::get_data(uv_handle!(self.handle));
if !dataptr.is_null() {
if let super::FsEventData(d) = unsafe { &mut (*dataptr).addl } {
d.fs_event_cb = cb;
}
}
crate::uvret(unsafe { uv_fs_event_start(self.handle, uv_cb, path.as_ptr(), flags.bits()) })
.map_err(|e| Box::new(e) as _)
}

@iceghost
Copy link
Author

iceghost commented Mar 30, 2024

The only reason I see is CString::new usage, but we can safely .unwrap() thanks to the UTF-8 guarantee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant