Implement fmt::Pointer for pointers to unsized types
This allows printing pointers to unsized types with the {:p} formatting
directive. The following impls are extended to unsized types:
- impl<'a, T: ?Sized> Pointer for &'a T
- impl<'a, T: ?Sized> Pointer for &'a mut T
- impl<T: ?Sized> Pointer for *const T
- impl<T: ?Sized> Pointer for *mut T
- impl<T: ?Sized> fmt::Pointer for Box<T>
- impl<T: ?Sized> fmt::Pointer for Rc<T>
- impl<T: ?Sized> fmt::Pointer for Arc<T>
This commit is contained in:
@@ -20,3 +20,11 @@ fn test_format_flags() {
|
||||
|
||||
assert_eq!(format!("{: >3}", 'a'), " a");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pointer_formats_data_pointer() {
|
||||
let b: &[u8] = b"";
|
||||
let s: &str = "";
|
||||
assert_eq!(format!("{:p}", s), format!("{:p}", s.as_ptr()));
|
||||
assert_eq!(format!("{:p}", b), format!("{:p}", b.as_ptr()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user