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

Replace uWrite impl for String by generic impl for all Write impls #19

Closed

Conversation

therealprof
Copy link
Contributor

Alternative version using core::fmt::Error as return type instead of
Infallible.

Signed-off-by: Daniel Egger daniel@eggers-club.de

Alternative version using core::fmt::Error as return type instead of
Infallible.

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
@japaric
Copy link
Owner

japaric commented Jan 23, 2020

I agree with the intention of the PR (bridging fmt::Write and uWrite) but I don't think we should use a blanket implementation for that because it makes impossible to implement both uWrite<Error = Infallible> (or some other helpful error type) and fmt::Write for some type at the same time ("overlapping (trait) implementation" rustc error).

Instead we should add an adapter type to ufmt-utils; something along the lines of:

use core::fmt;

pub struct ImBadAtNamingThingsAdapter<W>(pub W) where W: fmt::Write;

impl<W> uWrite for ImBadAtNamingThingsAdapter<W> where W: fmt::Write {
    type Error = fmt::Error;

    // NOTE should also include `write_char`

    fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
        self.0.write_str(s)
    }
}

// then this would work
let mut s = MyStringLikeType::new();
uwrite!(ImBadAtNamingThingsAdapter(&mut s), "{:?}", something_that_impls_udebug);

The uWrite for String implementation should not be removed.

@therealprof
Copy link
Contributor Author

Sounds good to me.

@therealprof
Copy link
Contributor Author

How does #21 sound?

@japaric
Copy link
Owner

japaric commented Feb 11, 2020

Closing in favor of #21

@japaric japaric closed this Feb 11, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants