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

Result<T>,Option<T> & Exceptions #139

Open
nearest-river opened this issue Nov 25, 2023 · 0 comments
Open

Result<T>,Option<T> & Exceptions #139

nearest-river opened this issue Nov 25, 2023 · 0 comments

Comments

@nearest-river
Copy link

nearest-river commented Nov 25, 2023

It would be great if we could throw exception from rust..

#[deno_bindgen]
pub fn div(a: i32,b: i32)-> i32 {
 if b==0 {
   deno_bindgen::throw("cannot divide by zero")
 } else {
   a/b
 }
}

And an Exception trait would be great just like wasm_bindgen

trait Exception<T> {
  fn unrwap_or_throw(self)-> T;
}

impl<T,E> Exception<T> for Result<T,E> {...}
impl<T> Exception<T> for Option<T> {...}

 #[deno_bindgen]
pub fn read(path: &str)-> String {
  std::fs::read_to_string(path).unwrap_or_throw()
}
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