/// to be `0.0`.
use std::from_str::FromStr;
+use std::vec_ng::Vec;
#[deriving(Clone, Eq)]
pub struct CrateId {
impl FromStr for CrateId {
fn from_str(s: &str) -> Option<CrateId> {
let pieces: Vec<&str> = s.splitn('#', 1).collect();
- let path = pieces[0].to_owned();
+ let path = pieces.get(0).to_owned();
if path.starts_with("/") || path.ends_with("/") ||
path.starts_with(".") || path.is_empty() {
}
let path_pieces: Vec<&str> = path.rsplitn('/', 1).collect();
- let inferred_name = path_pieces[0];
+ let inferred_name = *path_pieces.get(0);
let (name, version) = if pieces.len() == 1 {
(inferred_name.to_owned(), None)
} else {
- let hash_pieces: Vec<&str> = pieces[1].splitn(':', 1).collect();
+ let hash_pieces: Vec<&str> = pieces.get(1)
+ .splitn(':', 1)
+ .collect();
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
- ("", hash_pieces[0])
+ ("", *hash_pieces.get(0))
} else {
- (hash_pieces[0], hash_pieces[1])
+ (*hash_pieces.get(0), *hash_pieces.get(1))
};
let name = if !hash_name.is_empty() {
};
Some(CrateId {
- path: path,
+ path: path.clone(),
name: name,
version: version,
})