in src/main.rs [112:153]
fn parse_mappings<T: AsRef<str>, U: IntoIterator<Item=T>>(args: U)
-> Result<Vec<sandboxfs::Mapping>, UsageError> {
let mut mappings = Vec::new();
for arg in args {
let arg = arg.as_ref();
let fields: Vec<&str> = arg.split(':').collect();
if fields.len() != 3 {
let message = format!("bad mapping {}: expected three colon-separated fields", arg);
return Err(UsageError { message });
}
let writable = {
if fields[0] == "ro" {
false
} else if fields[0] == "rw" {
true
} else {
let message = format!("bad mapping {}: type was {} but should be ro or rw",
arg, fields[0]);
return Err(UsageError { message });
}
};
let path = PathBuf::from(fields[1]);
let underlying_path = PathBuf::from(fields[2]);
match sandboxfs::Mapping::from_parts(path, underlying_path, writable) {
Ok(mapping) => mappings.push(mapping),
Err(e) => {
// TODO(jmmv): Figure how to best leverage failure's cause propagation. May need
// to define a custom ErrorKind to represent UsageError, instead of having a special
// error type.
let message = format!("bad mapping {}: {}", arg, e);
return Err(UsageError { message });
}
}
}
Ok(mappings)
}