1use crate::error::Error;
4use crate::fmt;
5
6#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::marker::Copy for Utf8Error { }Copy, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::cmp::Eq for Utf8Error {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<usize>;
let _: crate::cmp::AssertParamIsEq<Option<u8>>;
}
}Eq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::cmp::PartialEq for Utf8Error {
#[inline]
fn eq(&self, other: &Utf8Error) -> bool {
self.valid_up_to == other.valid_up_to &&
self.error_len == other.error_len
}
}PartialEq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::clone::Clone for Utf8Error {
#[inline]
fn clone(&self) -> Utf8Error {
let _: crate::clone::AssertParamIsClone<usize>;
let _: crate::clone::AssertParamIsClone<Option<u8>>;
*self
}
}Clone, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::fmt::Debug for Utf8Error {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Utf8Error",
"valid_up_to", &self.valid_up_to, "error_len", &&self.error_len)
}
}Debug)]
46#[stable(feature = "rust1", since = "1.0.0")]
47pub struct Utf8Error {
48 pub(super) valid_up_to: usize,
49 pub(super) error_len: Option<u8>,
50}
51
52impl Utf8Error {
53 #[stable(feature = "utf8_error", since = "1.5.0")]
76 #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")]
77 #[must_use]
78 #[inline]
79 pub const fn valid_up_to(&self) -> usize {
80 self.valid_up_to
81 }
82
83 #[stable(feature = "utf8_error_error_len", since = "1.20.0")]
99 #[rustc_const_stable(feature = "const_str_from_utf8_shared", since = "1.63.0")]
100 #[must_use]
101 #[inline]
102 pub const fn error_len(&self) -> Option<usize> {
103 match self.error_len {
105 Some(len) => Some(len as usize),
106 None => None,
107 }
108 }
109}
110
111#[stable(feature = "rust1", since = "1.0.0")]
112impl fmt::Display for Utf8Error {
113 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114 if let Some(error_len) = self.error_len {
115 f.write_fmt(format_args!("invalid utf-8 sequence of {0} bytes from index {1}",
error_len, self.valid_up_to))write!(
116 f,
117 "invalid utf-8 sequence of {} bytes from index {}",
118 error_len, self.valid_up_to
119 )
120 } else {
121 f.write_fmt(format_args!("incomplete utf-8 byte sequence from index {0}",
self.valid_up_to))write!(f, "incomplete utf-8 byte sequence from index {}", self.valid_up_to)
122 }
123 }
124}
125
126#[stable(feature = "rust1", since = "1.0.0")]
127impl Error for Utf8Error {}
128
129#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::fmt::Debug for ParseBoolError {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f, "ParseBoolError")
}
}Debug, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::clone::Clone for ParseBoolError {
#[inline]
fn clone(&self) -> ParseBoolError { ParseBoolError }
}Clone, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::cmp::PartialEq for ParseBoolError {
#[inline]
fn eq(&self, other: &ParseBoolError) -> bool { true }
}PartialEq, #[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::cmp::Eq for ParseBoolError {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq)]
133#[non_exhaustive]
134#[stable(feature = "rust1", since = "1.0.0")]
135pub struct ParseBoolError;
136
137#[stable(feature = "rust1", since = "1.0.0")]
138impl fmt::Display for ParseBoolError {
139 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140 "provided string was not `true` or `false`".fmt(f)
141 }
142}
143
144#[stable(feature = "rust1", since = "1.0.0")]
145impl Error for ParseBoolError {}