Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
update to current rust
Browse files Browse the repository at this point in the history
  • Loading branch information
globin committed Feb 22, 2015
1 parent 5c6650a commit 77964e1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ keywords = ["puppetfile", "parser", "r10k"]
[dependencies]
semver = "0.1.13"
url = "0.2.17"
hyper = "0.1.9"
hyper = "0.2.0"
log = "0.2.1"
rustc-serialize = "0.2.10"
peg = "0.1.5"
6 changes: 2 additions & 4 deletions src/bin/pumuckl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(slicing_syntax)]

extern crate puppetfile;
extern crate semver;

Expand All @@ -16,13 +14,13 @@ fn main() {
let path = if args.len() == 1 {
Path::new("Puppetfile")
} else {
Path::new(&args[1][])
Path::new(&args[1])
};
let file_raw_bytes = match File::open(&path).read_to_end() {
Ok(bytes) => bytes,
Err(error) => panic!("{}", error)
};
let puppetfile_contents = str::from_utf8(&file_raw_bytes[]).unwrap();
let puppetfile_contents = str::from_utf8(&file_raw_bytes).unwrap();
let puppetfile = Puppetfile::parse(puppetfile_contents).unwrap();

let modules = puppetfile.modules.clone();
Expand Down
6 changes: 3 additions & 3 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ module_info -> Vec<ModuleInfo>
version -> ModuleInfo
= version:string __ {
if semver::Version::parse(&version[]).is_ok() {
ModuleInfo::Version(VersionReq::parse(&format!("={}", version)[]).unwrap())
if semver::Version::parse(&version).is_ok() {
ModuleInfo::Version(VersionReq::parse(&format!("={}", version)).unwrap())
} else {
ModuleInfo::Version(VersionReq::parse(&version[]).unwrap())
ModuleInfo::Version(VersionReq::parse(&version).unwrap())
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![crate_name = "puppetfile"]
#![deny(missing_docs)]
#![feature(plugin, slicing_syntax)]
#![feature(plugin)]

#![plugin(peg_syntax_ext)]

Expand Down Expand Up @@ -130,7 +130,7 @@ impl FromError<(ErrorKind, String)> for PuppetfileError {

impl Error for PuppetfileError {
fn description(&self) -> &str {
&self.desc[]
&self.desc
}

fn cause(&self) -> Option<&Error> {
Expand All @@ -148,19 +148,19 @@ impl Module {
/// The current version of the module returned from the forge API
pub fn forge_version(&self, forge_url: &str) -> Result<semver::Version, PuppetfileError> {
let url = try!(self.version_url(forge_url));
let mut response = try!(Client::new().get(&url[]).send());
let mut response = try!(Client::new().get(&url[..]).send());
let response_string = try!(response.read_to_string());
let version_struct: ForgeVersionResponse = try!(json::decode(&response_string[]));
let version = try!(semver::Version::parse(&version_struct.version[]));
let version_struct: ForgeVersionResponse = try!(json::decode(&response_string));
let version = try!(semver::Version::parse(&version_struct.version));

Ok(version)
}

/// Builds the URL for the forge API for fetching the version
pub fn version_url(&self, forge_url: &str) -> Result<String, PuppetfileError> {
let stripped_url = match forge_url[].ends_with("/") {
let stripped_url = match forge_url.ends_with("/") {
true => &forge_url[..forge_url.len() - 1],
_ => &forge_url[]
_ => &forge_url[..]
};
let (user, mod_name) = match self.user_name_pair() {
Some((user, mod_name)) => (user, mod_name),
Expand All @@ -172,8 +172,8 @@ impl Module {

/// Returns user and module name from 'user/mod_name'
pub fn user_name_pair(&self) -> Option<(&str, &str)> {
if self.name[].contains("/") {
let mut parts = self.name[].split('/');
if self.name.contains("/") {
let mut parts = self.name.split('/');
Some((parts.next().unwrap(), parts.next().unwrap()))
} else {
None
Expand Down

0 comments on commit 77964e1

Please sign in to comment.