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 format_escaped_char with a safe implementation #270

Closed
dtolnay opened this issue Feb 28, 2017 · 0 comments
Closed

Replace format_escaped_char with a safe implementation #270

dtolnay opened this issue Feb 28, 2017 · 0 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 28, 2017

#267 added this implementation:

let mut buf = [0; 4];
write!(&mut buf[..], "{}", value).unwrap();
let s = unsafe { str::from_utf8_unchecked(&buf[0..value.len_utf8()]) };
format_escaped_str(wr, formatter, s)

Once we drop support for <1.15.0, the implementation can be safe:

format_escaped_str(wr, formatter, value.encode_utf8(&mut [0; 4]))
erickt added a commit to erickt/json that referenced this issue Jun 10, 2017
Now that Rust 1.18 has come out, and according to our policy of supporting
the past 3 versions of rust, we can finally switch to using
`char::encode_utf8` to encode a character into a string.

Closes serde-rs#270.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant