Deprecate Read::chars and char::decode_utf8
Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
This commit is contained in:
parent
21dae950be
commit
7cbeddb7b7
6 changed files with 32 additions and 1 deletions
|
@ -17,11 +17,17 @@ use super::from_u32_unchecked;
|
||||||
/// An iterator over an iterator of bytes of the characters the bytes represent
|
/// An iterator over an iterator of bytes of the characters the bytes represent
|
||||||
/// as UTF-8
|
/// as UTF-8
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub struct DecodeUtf8<I: Iterator<Item = u8>>(::iter::Peekable<I>);
|
pub struct DecodeUtf8<I: Iterator<Item = u8>>(::iter::Peekable<I>);
|
||||||
|
|
||||||
/// Decodes an `Iterator` of bytes as UTF-8.
|
/// Decodes an `Iterator` of bytes as UTF-8.
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
|
#[allow(deprecated)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter> {
|
pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter> {
|
||||||
DecodeUtf8(i.into_iter().peekable())
|
DecodeUtf8(i.into_iter().peekable())
|
||||||
|
@ -29,10 +35,14 @@ pub fn decode_utf8<I: IntoIterator<Item = u8>>(i: I) -> DecodeUtf8<I::IntoIter>
|
||||||
|
|
||||||
/// `<DecodeUtf8 as Iterator>::next` returns this for an invalid input sequence.
|
/// `<DecodeUtf8 as Iterator>::next` returns this for an invalid input sequence.
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub struct InvalidSequence(());
|
pub struct InvalidSequence(());
|
||||||
|
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
|
impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
|
||||||
type Item = Result<char, InvalidSequence>;
|
type Item = Result<char, InvalidSequence>;
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -127,6 +137,7 @@ impl<I: Iterator<Item = u8>> Iterator for DecodeUtf8<I> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {}
|
impl<I: FusedIterator<Item = u8>> FusedIterator for DecodeUtf8<I> {}
|
||||||
|
|
||||||
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
|
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
|
||||||
|
|
|
@ -51,6 +51,9 @@ pub use unicode::tables::UNICODE_VERSION;
|
||||||
#[unstable(feature = "unicode_version", issue = "49726")]
|
#[unstable(feature = "unicode_version", issue = "49726")]
|
||||||
pub use unicode::version::UnicodeVersion;
|
pub use unicode::version::UnicodeVersion;
|
||||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
|
pub use self::decode::{decode_utf8, DecodeUtf8, InvalidSequence};
|
||||||
|
|
||||||
use fmt::{self, Write};
|
use fmt::{self, Write};
|
||||||
|
|
|
@ -364,6 +364,7 @@ fn eu_iterator_specializations() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn test_decode_utf8() {
|
fn test_decode_utf8() {
|
||||||
macro_rules! assert_decode_utf8 {
|
macro_rules! assert_decode_utf8 {
|
||||||
($input_bytes: expr, $expected_str: expr) => {
|
($input_bytes: expr, $expected_str: expr) => {
|
||||||
|
|
|
@ -1251,6 +1251,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn read_char_buffered() {
|
fn read_char_buffered() {
|
||||||
let buf = [195, 159];
|
let buf = [195, 159];
|
||||||
let reader = BufReader::with_capacity(1, &buf[..]);
|
let reader = BufReader::with_capacity(1, &buf[..]);
|
||||||
|
@ -1258,6 +1259,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn test_chars() {
|
fn test_chars() {
|
||||||
let buf = [195, 159, b'a'];
|
let buf = [195, 159, b'a'];
|
||||||
let reader = BufReader::with_capacity(1, &buf[..]);
|
let reader = BufReader::with_capacity(1, &buf[..]);
|
||||||
|
|
|
@ -566,6 +566,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn test_read_char() {
|
fn test_read_char() {
|
||||||
let b = &b"Vi\xE1\xBB\x87t"[..];
|
let b = &b"Vi\xE1\xBB\x87t"[..];
|
||||||
let mut c = Cursor::new(b).chars();
|
let mut c = Cursor::new(b).chars();
|
||||||
|
@ -577,6 +578,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn test_read_bad_char() {
|
fn test_read_bad_char() {
|
||||||
let b = &b"\x80"[..];
|
let b = &b"\x80"[..];
|
||||||
let mut c = Cursor::new(b).chars();
|
let mut c = Cursor::new(b).chars();
|
||||||
|
|
|
@ -840,6 +840,9 @@ pub trait Read {
|
||||||
of where errors happen is currently \
|
of where errors happen is currently \
|
||||||
unclear and may change",
|
unclear and may change",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
|
#[allow(deprecated)]
|
||||||
fn chars(self) -> Chars<Self> where Self: Sized {
|
fn chars(self) -> Chars<Self> where Self: Sized {
|
||||||
Chars { inner: self }
|
Chars { inner: self }
|
||||||
}
|
}
|
||||||
|
@ -2010,16 +2013,22 @@ impl<R: Read> Iterator for Bytes<R> {
|
||||||
/// [chars]: trait.Read.html#method.chars
|
/// [chars]: trait.Read.html#method.chars
|
||||||
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub struct Chars<R> {
|
pub struct Chars<R> {
|
||||||
inner: R,
|
inner: R,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An enumeration of possible errors that can be generated from the `Chars`
|
/// An enumeration of possible errors that can be generated from the `Chars`
|
||||||
/// adapter.
|
/// adapter.
|
||||||
#[derive(Debug)]
|
|
||||||
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[rustc_deprecated(since = "1.27.0", reason = "Use str::from_utf8 instead:
|
||||||
|
https://doc.rust-lang.org/nightly/std/str/struct.Utf8Error.html#examples")]
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[allow(deprecated)]
|
||||||
pub enum CharsError {
|
pub enum CharsError {
|
||||||
/// Variant representing that the underlying stream was read successfully
|
/// Variant representing that the underlying stream was read successfully
|
||||||
/// but it did not contain valid utf8 data.
|
/// but it did not contain valid utf8 data.
|
||||||
|
@ -2031,6 +2040,7 @@ pub enum CharsError {
|
||||||
|
|
||||||
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl<R: Read> Iterator for Chars<R> {
|
impl<R: Read> Iterator for Chars<R> {
|
||||||
type Item = result::Result<char, CharsError>;
|
type Item = result::Result<char, CharsError>;
|
||||||
|
|
||||||
|
@ -2063,6 +2073,7 @@ impl<R: Read> Iterator for Chars<R> {
|
||||||
|
|
||||||
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl std_error::Error for CharsError {
|
impl std_error::Error for CharsError {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
|
@ -2080,6 +2091,7 @@ impl std_error::Error for CharsError {
|
||||||
|
|
||||||
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
#[unstable(feature = "io", reason = "awaiting stability of Read::chars",
|
||||||
issue = "27802")]
|
issue = "27802")]
|
||||||
|
#[allow(deprecated)]
|
||||||
impl fmt::Display for CharsError {
|
impl fmt::Display for CharsError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue