From e8dcca18723cbaa7ed981f4d2c86f52ce8c55948 Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Tue, 16 Jun 2020 01:27:12 -0500 Subject: [PATCH] Use OsString for arguments rather than String --- src/uucore/src/lib/lib.rs | 15 +++++++++++++++ src/uucore/src/uucore_procs/src/lib.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index c5b26f87e..0b1ab63af 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -70,7 +70,22 @@ pub use crate::features::wide; //## core functions +use std::ffi::OsString; + +pub trait Args: Iterator + Sized { + fn collect_str(self) -> Vec { + // FIXME: avoid unwrap() + self.map(|s| s.into_string().unwrap()).collect() + } +} + +impl + Sized> Args for T { } + // args() ... pub fn args() -> impl Iterator { wild::args() } + +pub fn args_os() -> impl Iterator { + wild::args_os() +} diff --git a/src/uucore/src/uucore_procs/src/lib.rs b/src/uucore/src/uucore_procs/src/lib.rs index d867c7d10..aa77316ee 100644 --- a/src/uucore/src/uucore_procs/src/lib.rs +++ b/src/uucore/src/uucore_procs/src/lib.rs @@ -69,7 +69,7 @@ pub fn main(stream: proc_macro::TokenStream) -> proc_macro::TokenStream { }; proc_dbg!(&expr); - let f = quote::quote! { #expr(uucore::args().collect()) }; + let f = quote::quote! { #expr(uucore::args_os()) }; proc_dbg!(&f); // generate a uutils utility `main()` function, tailored for the calling utility