-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create
sys::args::Args
wrapper in sys_common
- Loading branch information
Showing
3 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::convert::AsRef; | ||
use crate::ffi::OsString; | ||
use crate::fmt; | ||
use crate::sys::args as sys; | ||
|
||
pub struct Args(sys::Args); | ||
|
||
impl !Send for Args {} | ||
impl !Sync for Args {} | ||
|
||
impl Args { | ||
pub fn get() -> Args { | ||
Args(sys::args()) | ||
} | ||
} | ||
|
||
impl fmt::Debug for Args { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let args = &AsRef::<[OsString]>::as_ref(self); | ||
args.fmt(f) | ||
} | ||
} | ||
|
||
impl AsRef<[OsString]> for Args { | ||
fn as_ref(&self) -> &[OsString] { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl Iterator for Args { | ||
type Item = OsString; | ||
fn next(&mut self) -> Option<OsString> { | ||
self.0.next() | ||
} | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.0.size_hint() | ||
} | ||
} | ||
|
||
impl ExactSizeIterator for Args { | ||
fn len(&self) -> usize { | ||
self.0.len() | ||
} | ||
} | ||
|
||
impl DoubleEndedIterator for Args { | ||
fn next_back(&mut self) -> Option<OsString> { | ||
self.0.next_back() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
#[cfg(test)] | ||
mod tests; | ||
|
||
pub mod args; | ||
pub mod backtrace; | ||
pub mod bytestring; | ||
pub mod condvar; | ||
|