Remove traces of ~str

This commit is contained in:
Yehuda Katz 2014-05-19 23:14:49 -07:00
parent cfeabbc21b
commit ca668c6605
14 changed files with 71 additions and 70 deletions

View file

@ -29,7 +29,7 @@ fn execute(options: Options) -> CLIResult<Option<()>> {
None => try!(find_project(os::getcwd(), "Cargo.toml".to_owned())
.map(|path| path.join("Cargo.toml"))
.to_result(|err|
CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err.to_str()), 102)))
CLIError::new("Could not find Cargo.toml in this directory or any parent directory", Some(err), 102)))
};
compile(root.as_str().unwrap().as_slice()).map(|_| None).to_cli(101)

View file

@ -24,8 +24,8 @@ fn main() {
fn execute(options: Options) -> CLIResult<Option<Package>> {
read_manifest(options.manifest_path.as_slice()).map(|m| Some(m))
.map_err(|err| CLIError {
msg: err.get_desc().to_owned(),
detail: err.get_detail().map(|s| s.to_owned()),
msg: err.get_desc().to_strbuf(),
detail: err.get_detail().map(|s| s.to_strbuf()),
exit_code: 1
})
}

View file

@ -14,11 +14,11 @@ use getopts::{reqopt,getopts};
fn main() {
let arguments: Vec<StrBuf> = args().iter().map(|a| a.to_strbuf()).collect();
let opts = ~[
let opts = vec!(
reqopt("m", "manifest", "the location of the manifest", "MANIFEST")
];
);
let matches = match getopts(arguments.tail(), opts) {
let matches = match getopts(arguments.tail(), opts.as_slice()) {
Ok(m) => m,
Err(_) => {
fail("missing-argument", "manifest");

View file

@ -18,7 +18,7 @@ fn main() {
#[deriving(Encodable)]
struct ProjectLocation {
root: ~str
root: StrBuf
}
/**
@ -32,17 +32,17 @@ fn execute() {
Err(err) => return handle_error(err)
};
if cmd == "config-for-key".to_owned() { execute_main_without_stdin(config_for_key) }
else if cmd == "config-list".to_owned() { execute_main_without_stdin(config_list) }
else if cmd == "locate-project".to_owned() { execute_main_without_stdin(locate_project) }
if cmd == "config-for-key".to_strbuf() { execute_main_without_stdin(config_for_key) }
else if cmd == "config-list".to_strbuf() { execute_main_without_stdin(config_list) }
else if cmd == "locate-project".to_strbuf() { execute_main_without_stdin(locate_project) }
}
fn process(mut args: Vec<~str>) -> CLIResult<(~str, Vec<~str>)> {
args = Vec::from_slice(args.tail());
let head = try!(args.iter().nth(0).to_result(|_| CLIError::new("No subcommand found", None, 1))).to_owned();
fn process(args: Vec<~str>) -> CLIResult<(StrBuf, Vec<StrBuf>)> {
let args: Vec<StrBuf> = args.tail().iter().map(|a| a.to_strbuf()).collect();
let head = try!(args.iter().nth(0).to_result(|_| CLIError::new("No subcommand found", None::<&str>, 1))).to_owned();
let tail = Vec::from_slice(args.tail());
Ok((head, tail))
Ok((head.to_strbuf(), tail))
}
#[deriving(Encodable)]
@ -64,7 +64,7 @@ impl FlagConfig for ConfigForKeyFlags {
fn config_for_key(args: ConfigForKeyFlags) -> CLIResult<Option<ConfigOut>> {
let value = try!(config::get_config(os::getcwd(), args.key.as_slice()).to_result(|err|
CLIError::new("Couldn't load configuration", Some(err.to_str()), 1)));
CLIError::new("Couldn't load configuration", Some(err), 1)));
if args.human {
println!("{}", value);
@ -89,7 +89,7 @@ impl FlagConfig for ConfigListFlags {
fn config_list(args: ConfigListFlags) -> CLIResult<Option<ConfigOut>> {
let configs = try!(config::all_configs(os::getcwd()).to_result(|err|
CLIError::new("Couldn't load conifguration", Some(err.to_str()), 1)));
CLIError::new("Couldn't load conifguration", Some(err), 1)));
if args.human {
for (key, value) in configs.iter() {
@ -102,11 +102,11 @@ fn config_list(args: ConfigListFlags) -> CLIResult<Option<ConfigOut>> {
}
fn locate_project(_: NoFlags) -> CLIResult<Option<ProjectLocation>> {
let root = try!(find_project(os::getcwd(), "Cargo.toml".to_owned()).to_result(|err|
CLIError::new(err.to_str(), None, 1)));
let root = try!(find_project(os::getcwd(), "Cargo.toml").to_result(|err|
CLIError::new(err.to_str(), None::<&str>, 1)));
let string = try!(root.as_str().to_result(|_|
CLIError::new(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), None, 1)));
CLIError::new(format!("Your project path contains characters not representable in Unicode: {}", os::getcwd().display()), None::<&str>, 1)));
Ok(Some(ProjectLocation { root: string.to_owned() }))
Ok(Some(ProjectLocation { root: string.to_strbuf() }))
}

View file

@ -4,28 +4,28 @@ use util::CargoResult;
#[deriving(Eq,Clone,Show)]
pub struct Dependency {
name: ~str,
name: StrBuf,
req: VersionReq
}
impl Dependency {
pub fn new(name: &str, req: &VersionReq) -> Dependency {
Dependency {
name: name.to_owned(),
name: name.to_strbuf(),
req: req.clone()
}
}
pub fn parse(name: &str, version: &str) -> CargoResult<Dependency> {
Ok(Dependency {
name: name.to_owned(),
name: name.to_strbuf(),
req: try!(VersionReq::parse(version))
})
}
pub fn exact(name: &str, version: &Version) -> Dependency {
Dependency {
name: name.to_owned(),
name: name.to_strbuf(),
req: VersionReq::exact(version)
}
}
@ -41,15 +41,15 @@ impl Dependency {
#[deriving(Eq,Clone,Encodable)]
pub struct SerializedDependency {
name: ~str,
req: ~str
name: StrBuf,
req: StrBuf
}
impl SerializedDependency {
pub fn from_dependency(dep: &Dependency) -> SerializedDependency {
SerializedDependency {
name: dep.get_name().to_owned(),
req: dep.get_version_req().to_str()
name: dep.get_name().to_strbuf(),
req: format_strbuf!("{}", dep.get_version_req())
}
}
}

View file

@ -24,14 +24,15 @@ impl Show for CargoError {
}
pub struct CLIError {
pub msg: ~str,
pub detail: Option<~str>,
pub msg: StrBuf,
pub detail: Option<StrBuf>,
pub exit_code: uint
}
impl CLIError {
pub fn new<T: ToStr>(msg: T, detail: Option<~str>, exit_code: uint) -> CLIError {
CLIError { msg: msg.to_str(), detail: detail, exit_code: exit_code }
pub fn new<T: Show, U: Show>(msg: T, detail: Option<U>, exit_code: uint) -> CLIError {
let detail = detail.map(|d| format_strbuf!("{}", d));
CLIError { msg: format_strbuf!("{}", msg), detail: detail, exit_code: exit_code }
}
}
@ -42,11 +43,11 @@ impl Show for CLIError {
}
pub enum InternalError {
StringConversionError(~str, &'static str),
MissingManifest(Path, ~str),
StringConversionError(StrBuf, &'static str),
MissingManifest(Path, StrBuf),
WrappedIoError(IoError),
PathError(~str),
Described(~str),
PathError(StrBuf),
Described(StrBuf),
Other
}
@ -71,7 +72,7 @@ impl Show for InternalError {
}
impl CargoError {
pub fn cli(msg: ~str, detail: Option<~str>, exit_code: uint) -> CargoError {
pub fn cli(msg: StrBuf, detail: Option<StrBuf>, exit_code: uint) -> CargoError {
CargoCLIError(CLIError::new(msg, detail, exit_code))
}
@ -79,8 +80,8 @@ impl CargoError {
CargoInternalError(error)
}
pub fn described<T: ToStr>(description: T) -> CargoError {
CargoInternalError(Described(description.to_str()))
pub fn described<T: Show>(description: T) -> CargoError {
CargoInternalError(Described(format_strbuf!("{}", description)))
}
pub fn other() -> CargoError {
@ -90,7 +91,7 @@ impl CargoError {
pub fn cli_error(self) -> CLIError {
match self {
CargoInternalError(err) =>
CLIError::new("An unexpected error occurred", Some(err.to_str()), 100),
CLIError::new("An unexpected error occurred", Some(err), 100),
CargoCLIError(err) => err
}
}

View file

@ -23,12 +23,12 @@ pub struct Package {
#[deriving(Encodable)]
struct SerializedPackage {
name: ~str,
version: ~str,
name: StrBuf,
version: StrBuf,
dependencies: Vec<SerializedDependency>,
authors: Vec<StrBuf>,
targets: Vec<Target>,
root: ~str
root: StrBuf
}
impl<E, S: Encoder<E>> Encodable<S, E> for Package {
@ -38,12 +38,12 @@ impl<E, S: Encoder<E>> Encodable<S, E> for Package {
let name_ver = summary.get_name_ver();
SerializedPackage {
name: name_ver.get_name().to_owned(),
version: name_ver.get_version().to_str(),
name: name_ver.get_name().to_strbuf(),
version: format_strbuf!("{}", name_ver.get_version()),
dependencies: summary.get_dependencies().iter().map(|d| SerializedDependency::from_dependency(d)).collect(),
authors: Vec::from_slice(manifest.get_authors()),
targets: Vec::from_slice(manifest.get_targets()),
root: self.root.as_str().unwrap().to_owned()
root: self.root.as_str().unwrap().to_strbuf()
}.encode(s)
}
}

View file

@ -36,14 +36,14 @@ impl Summary {
}
pub trait SummaryVec {
fn names(&self) -> Vec<~str>;
fn names(&self) -> Vec<StrBuf>;
fn deps(&self) -> Vec<Dependency>;
}
impl SummaryVec for Vec<Summary> {
// TODO: Move to Registery
fn names(&self) -> Vec<~str> {
self.iter().map(|summary| summary.name_ver.get_name().to_owned()).collect()
fn names(&self) -> Vec<StrBuf> {
self.iter().map(|summary| summary.name_ver.get_name().to_strbuf()).collect()
}
// TODO: Delete

View file

@ -89,15 +89,15 @@ fn args() -> Vec<StrBuf> {
fn flags_from_args<T: RepresentsFlags>() -> CLIResult<T> {
let mut decoder = FlagDecoder::new::<T>(args().tail());
Decodable::decode(&mut decoder).to_result(|e: HammerError| CLIError::new(e.message, None, 1))
Decodable::decode(&mut decoder).to_result(|e: HammerError| CLIError::new(e.message, None::<&str>, 1))
}
fn json_from_stdin<T: RepresentsJSON>() -> CLIResult<T> {
let mut reader = io::stdin();
let input = try!(reader.read_to_str().to_result(|_| CLIError::new("Standard in did not exist or was not UTF-8", None, 1)));
let input = try!(reader.read_to_str().to_result(|_| CLIError::new("Standard in did not exist or was not UTF-8", None::<&str>, 1)));
let json = try!(json::from_str(input).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.clone()), 1)));
let json = try!(json::from_str(input).to_result(|_| CLIError::new("Could not parse standard in as JSON", Some(input.to_strbuf()), 1)));
let mut decoder = json::Decoder::new(json);
Decodable::decode(&mut decoder).to_result(|e: json::DecoderError| CLIError::new("Could not process standard in as input", Some(e.to_str()), 1))
Decodable::decode(&mut decoder).to_result(|e: json::DecoderError| CLIError::new("Could not process standard in as input", Some(e), 1))
}

View file

@ -6,10 +6,10 @@ use util::{toml_error,human_error,CargoResult,CargoError};
pub fn read_manifest(path: &str) -> CargoResult<Package> {
let root = try!(parse_from_file(path).map_err(|err: CargoError|
human_error(format!("Cargo.toml is not valid Toml"), format!("path={}", path), err)));
human_error("Cargo.toml is not valid Toml".to_strbuf(), format_strbuf!("path={}", path), err)));
let toml = try!(load_toml(root).map_err(|err: CargoError|
human_error(format!("Cargo.toml is not a valid Cargo manifest"), format!("path={}", path), err)));
human_error("Cargo.toml is not a valid Cargo manifest".to_strbuf(), format_strbuf!("path={}", path), err)));
toml.to_package(path)
}

View file

@ -97,5 +97,5 @@ fn rustc_to_cargo_err(args: &[StrBuf], cwd: &Path, err: CargoError) -> CargoErro
msg
};
human_error(msg.to_owned(), format!("root={}", cwd.display()), err)
human_error(msg, format_strbuf!("root={}", cwd.display()), err)
}

View file

@ -1,6 +1,6 @@
use util::{other_error,CargoResult,CargoError};
pub fn find_project(pwd: Path, file: ~str) -> CargoResult<Path> {
pub fn find_project(pwd: Path, file: &str) -> CargoResult<Path> {
let mut current = pwd.clone();
loop {

View file

@ -64,7 +64,7 @@ impl ProcessBuilder {
if exit.success() {
Ok(())
} else {
let msg = format!("Could not execute process `{}`", self.debug_string());
let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
Err(process_error(msg, exit, None))
}
}
@ -78,7 +78,7 @@ impl ProcessBuilder {
if output.status.success() {
Ok(output)
} else {
let msg = format!("Could not execute process `{}`", self.debug_string());
let msg = format_strbuf!("Could not execute process `{}`", self.debug_string());
Err(process_error(msg, output.status.clone(), Some(output)))
}
}

View file

@ -33,7 +33,7 @@ pub fn io_error(err: IoError) -> CargoError {
}
}
pub fn process_error(detail: ~str, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
pub fn process_error(detail: StrBuf, exit: ProcessExit, output: Option<ProcessOutput>) -> CargoError {
CargoError {
kind: ProcessError(exit, output),
desc: BoxedDescription(detail),
@ -42,7 +42,7 @@ pub fn process_error(detail: ~str, exit: ProcessExit, output: Option<ProcessOutp
}
}
pub fn human_error(desc: ~str, detail: ~str, cause: CargoError) -> CargoError {
pub fn human_error(desc: StrBuf, detail: StrBuf, cause: CargoError) -> CargoError {
CargoError {
kind: HumanReadableError,
desc: BoxedDescription(desc),
@ -64,14 +64,14 @@ pub fn toml_error(desc: &'static str, error: toml::Error) -> CargoError {
pub struct CargoError {
pub kind: CargoErrorKind,
desc: CargoErrorDescription,
detail: Option<~str>,
detail: Option<StrBuf>,
cause: Option<Box<CargoError>>
}
#[deriving(Show,Clone)]
enum CargoErrorDescription {
StaticDescription(&'static str),
BoxedDescription(~str)
BoxedDescription(StrBuf)
}
impl CargoError {
@ -86,24 +86,24 @@ impl CargoError {
self.detail.as_ref().map(|s| s.as_slice())
}
pub fn with_detail(mut self, detail: ~str) -> CargoError {
self.detail = Some(detail);
pub fn with_detail<T: Show>(mut self, detail: T) -> CargoError {
self.detail = Some(format_strbuf!("{}", detail));
self
}
pub fn to_cli(self, exit_code: uint) -> CLIError {
match self {
CargoError { kind: HumanReadableError, desc: BoxedDescription(desc), detail: detail, .. } => {
CLIError::new(desc, detail, exit_code)
CLIError::new(desc, detail.map(|d| d.to_strbuf()), exit_code)
},
CargoError { kind: InternalError, desc: StaticDescription(desc), detail: None, .. } => {
CLIError::new("An unexpected error occurred", Some(desc.to_owned()), exit_code)
CLIError::new("An unexpected error occurred", Some(desc), exit_code)
},
CargoError { kind: InternalError, desc: StaticDescription(desc), detail: Some(detail), .. } => {
CLIError::new("An unexpected error occurred", Some(format!("{}\n{}", desc, detail)), exit_code)
CLIError::new("An unexpected error occurred", Some(format_strbuf!("{}\n{}", desc, detail)), exit_code)
},
_ => {
CLIError::new("An unexpected error occurred", None, exit_code)
CLIError::new("An unexpected error occurred", None::<&str>, exit_code)
}
}
}
@ -155,7 +155,7 @@ pub struct CargoCliError {
kind: CargoCliErrorKind,
exit_status: uint,
desc: &'static str,
detail: Option<~str>,
detail: Option<StrBuf>,
cause: Option<CargoError>
}