Function dia_args::parse_stream
source · pub fn parse_stream<R>(stream: &mut R, max_size: Option<u64>) -> Result<Args>where
R: Read,
Expand description
§Parses a stream of strings, separated by null byte (0
)
This function can be useful for securely passing/parsing arguments across processes.
§Notes
- If
max_size
is zero, an error is returned. IfNone
,MAX_DIA_ARGS_FILE_SIZE
will be used. If the stream has more data than provided value, an error is returned. - If the stream contains an invalid UTF-8 string, an error is returned.
- The stream is used as-is. So you might want to use
BufReader
.
§Examples
let stream = b"run\0--faster=true";
let mut args = dia_args::parse_stream(&mut &stream[..], None)?;
assert_eq!(args.cmd(), Some("run"));
assert_eq!(args.take(&["--faster"])?, Some(true));