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

Motivation for associated error type? #27

Open
SimonSapin opened this issue Jan 20, 2021 · 1 comment
Open

Motivation for associated error type? #27

SimonSapin opened this issue Jan 20, 2021 · 1 comment

Comments

@SimonSapin
Copy link

I’m working on an other alternative to std::fmt (this time with arbitrary bytes output rather than Unicode, https://foss.heptapod.net/octobus/rust/format-bytes/) and considering having an associated type for errors v.s. a single error type. ufmt presents this as a feature:

A generic Formatter<'_, impl uWrite> instead of a single core::Formatter; the uWrite trait has an associated error type so each writer can choose its error type. For example, the implementation for std::String uses Infallible as its error type.

While the String case is neat, it doesn’t feel very valuable. I can live with an .unwrap() call in a few places with a comment "never panics because String::write_str never errors".

Are there other cases where using a different error type is useful?

@SimonSapin
Copy link
Author

A downside that I find more serious is that uDisplay cannot be object-safe, because of its generic method.

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