forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std: xous: add support for args and env
Process arguments and environment variables are both passed by way of Application Parameters. These are a TLV format that gets passed in as the second process argument. This patch combines both as they are very similar in their decode. Signed-off-by: Sean Cross <[email protected]>
- Loading branch information
Showing
5 changed files
with
500 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::ffi::OsString; | ||
use crate::sys::pal::xous::os::{get_application_parameters, params::ArgumentList}; | ||
use crate::{fmt, vec}; | ||
|
||
pub struct Args { | ||
parsed_args_list: vec::IntoIter<OsString>, | ||
} | ||
|
||
pub fn args() -> Args { | ||
let Some(params) = get_application_parameters() else { | ||
return Args { parsed_args_list: vec![].into_iter() }; | ||
}; | ||
|
||
for param in params { | ||
if let Ok(args) = ArgumentList::try_from(¶m) { | ||
let mut parsed_args = vec![]; | ||
for arg in args { | ||
parsed_args.push(arg.into()); | ||
} | ||
return Args { parsed_args_list: parsed_args.into_iter() }; | ||
} | ||
} | ||
Args { parsed_args_list: vec![].into_iter() } | ||
} | ||
|
||
impl fmt::Debug for Args { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
self.parsed_args_list.as_slice().fmt(f) | ||
} | ||
} | ||
|
||
impl Iterator for Args { | ||
type Item = OsString; | ||
fn next(&mut self) -> Option<OsString> { | ||
self.parsed_args_list.next() | ||
} | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.parsed_args_list.size_hint() | ||
} | ||
} | ||
|
||
impl DoubleEndedIterator for Args { | ||
fn next_back(&mut self) -> Option<OsString> { | ||
self.parsed_args_list.next_back() | ||
} | ||
} | ||
|
||
impl ExactSizeIterator for Args { | ||
fn len(&self) -> usize { | ||
self.parsed_args_list.len() | ||
} | ||
} |
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
Oops, something went wrong.