Skip to content

Commit 847d5b4

Browse files
committed
Derive Clone + PartialEq + Eq for std::string::FromUtf8Error
1 parent 6c0b779 commit 847d5b4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/liballoc/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub struct String {
319319
/// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
320320
/// ```
321321
#[stable(feature = "rust1", since = "1.0.0")]
322-
#[derive(Debug)]
322+
#[derive(Debug, Clone, PartialEq, Eq)]
323323
pub struct FromUtf8Error {
324324
bytes: Vec<u8>,
325325
error: Utf8Error,

src/liballoc/tests/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn test_from_utf8() {
5050

5151
let xs = b"hello\xFF".to_vec();
5252
let err = String::from_utf8(xs).unwrap_err();
53+
assert_eq!(err.as_bytes(), b"hello\xff");
54+
let err_clone = err.clone();
55+
assert_eq!(err, err_clone);
5356
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
57+
assert_eq!(err_clone.utf8_error().valid_up_to(), 5);
5458
}
5559

5660
#[test]

0 commit comments

Comments
 (0)