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

Use enums instead of Box<Error> for failure #55

Open
fschutt opened this issue Jul 3, 2018 · 8 comments
Open

Use enums instead of Box<Error> for failure #55

fschutt opened this issue Jul 3, 2018 · 8 comments

Comments

@fschutt
Copy link

fschutt commented Jul 3, 2018

I've hard-forked this repository at https://github.com/fschutt/clipboard2 and changed it to return a ClipboardError enum. The problem with Box<Error> is basically that it erases all type information - the library user can only get the description, which isn't of much use except for debugging.

I've replaced all usage of Box<Error> with an error enum which is not only type-safe and more descriptive (the library use now knows why the function could fail), but also more performant (no dynamic dispatch). I'd be happy to contribute the changes back into this repo, but for now I'm using the hard fork (I'll credit your repository though, since large amounts of that repo isn't technically my code).

@fschutt
Copy link
Author

fschutt commented Jul 3, 2018

Also you might want to update x11-clipboard - the new version (0.3.0-alpha) doesn't have any breaking changes, but has way less dependencies (decreased build time).

@Sh4pe
Copy link

Sh4pe commented Aug 6, 2018

I'd like this feature too. @fschutt, could you make a PR from this?

@aweinstock314
Copy link
Owner

@fschutt I'm willing to merge this (and it looks like your clipboard_metadata.rs is a useful component for adding typed clipboard data, e.g. images). Do you want to make the PR, or should I cherry-pick the commits from your repo?

@fschutt
Copy link
Author

fschutt commented Feb 11, 2019

Well, when I made the fork I basically squashed the entire history and rewrote a lot of things. Not sure how to rebase all of this without losing the history. I'm not against merging it of course, but I don't see how I could undo this without losing all of the history. @aweinstock314 I've never used cherry-picking, maybe you're better at git, so that may be an option. I'm fairly busy atm, feel free to merge my fork back in. It's just that you didn't respond for several months, so I thought this repo isn't maintained anymore, hence the fork.

@aweinstock314
Copy link
Owner

It looks like the squash of the history also squashed your changes to error-handling into the initial commit of clipboard2, so there is no history to preserve. I'll adapt your error-handling code in as one commit, and the format handling in another.

@chr4
Copy link

chr4 commented Jul 19, 2020

Thanks for working on this! I think the issue is solved in master, but it doesn't seem like a new version was released at crates.io, was it? When using v0.5.0, it still seems to use the Box error messages.

@qwerty01
Copy link

It does not look like it's fixed in master.
I've been working a bit on fixing it here: https://github.com/qwerty01/rust-clipboard
It's not that clean yet (I still have to go back and find the best practices for the way I chose to handle the error enums) and I don't have a mac to test the OSX changes, but it's at least providing an error type that is compatible with the ? operator for windows and linux.

@oovm
Copy link

oovm commented Jan 26, 2021

When I used in async function, it fails by:

error: future cannot be sent between threads safely
help: the trait `std::marker::Send` is not implemented for `dyn std::error::Error`

enum type can fix this

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

6 participants