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

Document and test HexWriter constructor #144

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

tcharding
Copy link
Member

Thanks to a blanket impl of Write for &mut W we can pass in a mutable reference to HexWriter::new even though the function signature suggests it takes ownership of the writer.

Document this as suggested in the Rust API guidelines doc.

While we are at it add a unit test to prove it.

ref: https://rust-lang.github.io/api-guidelines/interoperability.html#c-rw-value

@apoelstra
Copy link
Member

rustfmt is unhappy with this

@tcharding
Copy link
Member Author

Why do you idiots even use the formatter in CI ... oh wait

Thanks to a blanket impl of `Write` for `&mut W` we can pass in a
mutable reference to `HexWriter::new` even though the function signature
suggests it takes ownership of the writer.

Document this as suggested in the Rust API guidelines doc.

While we are at it add a unit test to prove it.

ref: https://rust-lang.github.io/api-guidelines/interoperability.html#c-rw-value
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 0f8d203; successfully ran local tests

@apoelstra apoelstra merged commit 62de2b8 into rust-bitcoin:master Jan 23, 2025
13 checks passed
fn hex_writer_accepts_and_mut() {
let mut dest_buf = ArrayString::<64>::new();
let mut dest = HexWriter::new(&mut dest_buf, Case::Lower);
let _got = dest.write(b"some data").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is actually testing that std still has the &mut T impl. I'm certain we don't need to test that. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It also proves, probably unnecessarily like you say, that the docs I wrote in this PR are correct.

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.

3 participants