diff options
| author | bors <bors@rust-lang.org> | 2017-06-22 10:34:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-22 10:34:21 +0000 |
| commit | 6f01c84fc8ae1b07d8165ceccb2e432f45a2ff1a (patch) | |
| tree | 65497205cc0fa9582e0612e82374799752ad36f2 /src/libstd/sys/windows | |
| parent | 03c8b92dc1c160c86d7ba6f08ee718a5324de136 (diff) | |
| parent | 275f9a04af6191e3aee3852a5a1713130f635164 (diff) | |
| download | rust-6f01c84fc8ae1b07d8165ceccb2e432f45a2ff1a.tar.gz rust-6f01c84fc8ae1b07d8165ceccb2e432f45a2ff1a.zip | |
Auto merge of #42798 - stepancheg:args-debug, r=sfackler
Better Debug for Args and ArgsOs Display actual args instead of two dots.
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/args.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libstd/sys/windows/args.rs b/src/libstd/sys/windows/args.rs index aa61f9adb82..4784633edc1 100644 --- a/src/libstd/sys/windows/args.rs +++ b/src/libstd/sys/windows/args.rs @@ -16,6 +16,7 @@ use slice; use ops::Range; use ffi::OsString; use libc::{c_int, c_void}; +use fmt; pub unsafe fn init(_argc: isize, _argv: *const *const u8) { } @@ -39,6 +40,36 @@ pub struct Args { cur: *mut *mut u16, } +pub struct ArgsInnerDebug<'a> { + args: &'a Args, +} + +impl<'a> fmt::Debug for ArgsInnerDebug<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("[")?; + let mut first = true; + for i in self.args.range.clone() { + if !first { + f.write_str(", ")?; + } + first = false; + + // Here we do allocation which could be avoided. + fmt::Debug::fmt(&unsafe { os_string_from_ptr(*self.args.cur.offset(i)) }, f)?; + } + f.write_str("]")?; + Ok(()) + } +} + +impl Args { + pub fn inner_debug(&self) -> ArgsInnerDebug { + ArgsInnerDebug { + args: self + } + } +} + unsafe fn os_string_from_ptr(ptr: *mut u16) -> OsString { let mut len = 0; while *ptr.offset(len) != 0 { len += 1; } |
