From: Carl Lerche Date: Thu, 8 May 2014 20:38:16 +0000 (-0700) Subject: Start migrating to new CargoResult X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1073 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=460f63d2fe352d80e97c7ba0ffa04efa05bf2c64;p=cargo.git Start migrating to new CargoResult --- diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index b43ca5af4..ffb58d79a 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -1,16 +1,15 @@ -use collections::HashMap; use std::fmt; use std::fmt::{Show,Formatter}; +use collections::HashMap; +use serialize::{Encoder,Encodable}; use core::{ Dependency, NameVer, Package, Summary }; -use core::errors::{CargoResult,CargoError,ToResult,PathError}; -use serialize::{Encoder,Encodable}; +use util::result::CargoResult; -// #[deriving(Decodable,Encodable,Eq,Clone)] #[deriving(Eq,Clone)] pub struct Manifest { summary: Summary, @@ -179,6 +178,9 @@ pub struct TomlManifest { impl TomlManifest { pub fn to_package(&self, path: &str) -> CargoResult { + // TODO: Convert hte argument to take a Path + let path = Path::new(path); + // Get targets let targets = normalize(&self.lib, &self.bin); // Get deps @@ -190,15 +192,15 @@ impl TomlManifest { }).collect() }).unwrap_or_else(|| vec!()); - let root = try!(Path::new(path.to_owned()).dirname_str().map(|s| s.to_owned()).to_result(|_| - CargoError::internal(PathError(format!("Couldn't convert {} to a directory name", path))))); + // TODO: https://github.com/mozilla/rust/issues/14049 + let root = Path::new(path.dirname()); Ok(Package::new( &Manifest::new( &Summary::new(&self.project.to_name_ver(), deps.as_slice()), targets.as_slice(), &Path::new("target")), - &Path::new(root))) + &root)) } } diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index aac3ef546..df596e0e8 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -3,3 +3,4 @@ pub mod graph; pub mod process_builder; pub mod config; pub mod important_paths; +pub mod result; diff --git a/src/cargo/util/result.rs b/src/cargo/util/result.rs new file mode 100644 index 000000000..7a35d460b --- /dev/null +++ b/src/cargo/util/result.rs @@ -0,0 +1,33 @@ +use std::io; + +pub type CargoResult = Result; + +#[deriving(Show)] +pub struct CargoError { + kind: CargoErrorKind, + desc: &'static str, + detail: Option<~str> +} + +#[deriving(Show)] +pub enum CargoErrorKind { + InternalError, + IoError(io::IoError), + OtherCargoError +} + +type CargoCliResult = Result; + +#[deriving(Show)] +pub struct CargoCliError { + kind: CargoCliErrorKind, + exit_status: uint, + desc: &'static str, + detail: Option<~str>, + cause: Option +} + +#[deriving(Show)] +pub enum CargoCliErrorKind { + OtherCargoCliError +}