Skip to content

Use escaped byte string representation for CString Debug #26965

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

Merged
merged 1 commit into from
Jul 12, 2015

Conversation

bluss
Copy link
Member

@bluss bluss commented Jul 11, 2015

Use escaped byte string representation for CString Debug

Faithfully represent the contents of the CString and CStr in their Debug
impl, by treating them as byte strings with our default escaping to
ascii representation.

Add impl Debug for CStr.

Fixes #26964.

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@bluss
Copy link
Member Author

bluss commented Jul 11, 2015

r? @alexcrichton

Can I avoid somehow adding a new feature name? I understand we might not want to add anything to ascii::EscapeDefault -- but at the same time, it's safer to use unsafe to guarantee utf-8 safety in the same module, than somewhere else.

Also think about the result of displaying a partly iterated ascii::EscapeDefault (it will still be ascii safe, but display a partial string).

@alexcrichton
Copy link
Member

Can I avoid somehow adding a new feature name?

Currently, no, but it's fine to just invent a name like you have. Due to there being no current precedent for implementing Debug for iterators, can this avoid the implementation on EscapeDefault for now? Something like this should be equivalent, right?

for byte in self.to_bytes().iter().flat_map(|b| ascii::escape_default(*b)) {
    write!(f, "{}", byte as char);
}

@bluss
Copy link
Member Author

bluss commented Jul 11, 2015

It's actually Display for the iterator. I think it's pretty appropriate, but I understand we can avoid it

Faithfully represent the contents of the CString and CStr in their Debug
impl, by treating them as byte strings with our default escaping to
ascii representation.

Add impl Debug for Cstr.

Fixes rust-lang#26964.
@bluss
Copy link
Member Author

bluss commented Jul 11, 2015

Updated! Not changing EscapeDefault then. Neat little iterator.

@alexcrichton
Copy link
Member

@bors: r+ 92c8a94

Thanks!

@bors
Copy link
Collaborator

bors commented Jul 12, 2015

⌛ Testing commit 92c8a94 with merge c75264c...

@bors
Copy link
Collaborator

bors commented Jul 12, 2015

💔 Test failed - auto-linux-64-opt

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Jul 11, 2015 at 11:02 PM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-linux-64-opt
http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5664


Reply to this email directly or view it on GitHub
#26965 (comment).

bors added a commit that referenced this pull request Jul 12, 2015
Use escaped byte string representation for CString Debug

Faithfully represent the contents of the CString and CStr in their Debug
impl, by treating them as byte strings with our default escaping to
ascii representation.

Add impl Debug for CStr.

Fixes #26964.
@bors
Copy link
Collaborator

bors commented Jul 12, 2015

⌛ Testing commit 92c8a94 with merge 2999003...

@bors bors merged commit 92c8a94 into rust-lang:master Jul 12, 2015
@bluss bluss deleted the cstring-debug branch July 12, 2015 13:29
@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 27, 2015
@bluss
Copy link
Member Author

bluss commented Jul 27, 2015

Suggested relnote: CStr now implements fmt::Debug.

Optional extra: CStr and CString now render as ascii escaped byte strings in Debug formatting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants