Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(rome_formatter): dbg_write API compatibility with write #2708

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

MichaReiser
Copy link
Contributor

Summary

This PR ensures that the buffer argument of dbg_write! is compatible with the buffer argument of write! so that the two can be swapped without any changes to the debugged code.

The current implementation hasn't been compatible because the dbg_write! macro called into Inspect::new that expected a &mut Buffer which requires the use of &mut buffer if an implementation uses a local Buffer variable.

This PR changes the macro implementation to use Buffer.inspect instead that works for any mutable Buffer.

Test Plan

I changed the dbg_write macro test to pass in buffer without &mut.

@MichaReiser MichaReiser self-assigned this Jun 14, 2022
@MichaReiser MichaReiser temporarily deployed to aws June 14, 2022 07:18 Inactive
@@ -433,6 +433,18 @@ pub trait BufferExtensions: Buffer + Sized {
{
Inspect::new(self, inspector)
}

/// Writes a sequence of elements into this buffer.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I sneaked that into this PR. This allows writing a sequence of elements without going over buffer.into_element

@MichaReiser MichaReiser temporarily deployed to aws June 14, 2022 07:21 Inactive
@github-actions
Copy link

github-actions bot commented Jun 14, 2022

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jun 14, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f51e55e
Status: ✅  Deploy successful!
Preview URL: https://cdfdfa9b.tools-8rn.pages.dev
Branch Preview URL: https://fix-write-dbg-mut-buffer.tools-8rn.pages.dev

View logs

This PR ensures that the `buffer` argument of `dbg_write!` is compatible with the `buffer` argument of `write!` so that the two can be swapped without any changes to the debugged code.

The current implementation hasn't been compatible because the `dbg_write!` macro called into `Inspect::new` that expected a `&mut Buffer` which requires the use of `&mut buffer` if an implementation uses a local `Buffer` variable.

This PR changes the macro implementation to use `Buffer.inspect` instead that works for any mutable `Buffer`.
@MichaReiser MichaReiser temporarily deployed to aws June 14, 2022 07:45 Inactive
@MichaReiser MichaReiser merged commit aacc0b0 into main Jun 14, 2022
@MichaReiser MichaReiser deleted the fix/write-dbg-mut-buffer branch June 14, 2022 14:52
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Jun 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants