-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from odarbelaeze/clippy-this-up
Clippy this up
- Loading branch information
Showing
17 changed files
with
185 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
[package] | ||
name = "vegas-lattice" | ||
version = "0.3.0" | ||
version = "0.4.0" | ||
authors = ["Oscar David Arbeláez Echeverri <[email protected]>"] | ||
description = "CLI and library to work with lattices" | ||
documentation = "https://github.com/pcm-ca/vegas-lattice-rs/wiki" | ||
homepage = "https://github.com/pcm-ca/vegas-lattice-rs/wiki" | ||
repository = "https://github.com/pcm-ca/vegas-lattice-rs" | ||
documentation = "https://github.com/odarbelaeze/vegas-lattice-rs/wiki" | ||
homepage = "https://github.com/odarbelaeze/vegas-lattice-rs/wiki" | ||
repository = "https://github.com/odarbelaeze/vegas-lattice-rs" | ||
readme = "README.md" | ||
keywords = ["lattice", "graph", "crystall", "materials"] | ||
categories = ["command-line-utilities", "science", "simulation"] | ||
license-file = "LICENSE.txt" | ||
|
||
[badges] | ||
travis-ci = { repository = "pcm-ca/vegas-lattice-rs", branch = "master" } | ||
is-it-maintained-issue-resolution = { repository = "pcm-ca/vegas-lattice-rs" } | ||
is-it-maintained-open-issues = { repository = "pcm-ca/vegas-lattice-rs" } | ||
travis-ci = { repository = "odarbelaeze/vegas-lattice-rs", branch = "master" } | ||
is-it-maintained-issue-resolution = { repository = "odarbelaeze/vegas-lattice-rs" } | ||
is-it-maintained-open-issues = { repository = "odarbelaeze/vegas-lattice-rs" } | ||
maintenance = { status = "actively-developed" } | ||
|
||
[dependencies] | ||
serde_json = "1.0" | ||
serde = "1.0" | ||
serde_derive = "1.0" | ||
itertools = "0.6" | ||
docopt = "0.8" | ||
image = "0.15" | ||
rand = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
// Let's abstract an alloy | ||
|
||
use rand::distributions::{Weighted}; | ||
use rand::distributions::Weighted; | ||
|
||
#[derive(Debug)] | ||
pub struct Alloy { | ||
items: Vec<Weighted<String>>, | ||
} | ||
|
||
|
||
impl Alloy { | ||
pub fn new(kinds: Vec<&str>, ratios: Vec<u32>) -> Self { | ||
let items: Vec<_> = kinds | ||
.into_iter() | ||
.zip(ratios.into_iter()) | ||
.map(|(item, weight)| Weighted { | ||
weight: weight, | ||
item: item.to_owned() | ||
weight, | ||
item: item.to_owned(), | ||
}) | ||
.collect(); | ||
Self { items: items, } | ||
Self { items } | ||
} | ||
|
||
pub fn choices(self) -> Vec<Weighted<String>> { | ||
self.items | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,54 @@ | ||
use std::fmt; | ||
use std::error::Error as StdError; | ||
|
||
use serde_json::Error as SerdeError; | ||
|
||
use std::error::Error as StdError; | ||
use std::fmt; | ||
use std::io::Error as IoError; | ||
|
||
#[derive(Debug)] | ||
pub enum LatticeError { | ||
IoError(IoError), | ||
JsonParseError(SerdeError), | ||
InconsistentVertices, | ||
NegativeSize, | ||
} | ||
|
||
impl StdError for LatticeError { | ||
fn description(&self) -> &str { | ||
match self { | ||
LatticeError::IoError(_) => "There was an error reading your file", | ||
LatticeError::JsonParseError(_) => "There was a problem parsing json", | ||
LatticeError::InconsistentVertices => "These vertices are inconsistent", | ||
LatticeError::NegativeSize => "What are you up to don't give me a negative size", | ||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&StdError> { | ||
match self { | ||
LatticeError::IoError(err) => Some(err), | ||
LatticeError::JsonParseError(err) => Some(err), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for LatticeError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
LatticeError::IoError(_) => f.write_str("IoError"), | ||
LatticeError::JsonParseError(_) => f.write_str("JsonParseError"), | ||
LatticeError::InconsistentVertices => f.write_str("InconsistentVertices"), | ||
LatticeError::NegativeSize => f.write_str("NegativeSize"), | ||
} | ||
} | ||
} | ||
|
||
|
||
impl StdError for LatticeError { | ||
fn description(&self) -> &str { | ||
match *self { | ||
LatticeError::JsonParseError(_) => "failed to parse JSON", | ||
LatticeError::InconsistentVertices => "the vertices are inconsistent", | ||
LatticeError::NegativeSize => "a negative size value is hard to grasp", | ||
} | ||
impl From<SerdeError> for LatticeError { | ||
fn from(err: SerdeError) -> Self { | ||
LatticeError::JsonParseError(err) | ||
} | ||
} | ||
|
||
fn cause(&self) -> Option<&StdError> { | ||
match self { | ||
&LatticeError::JsonParseError(ref err) => Some(err), | ||
_ => None, | ||
} | ||
impl From<IoError> for LatticeError { | ||
fn from(err: IoError) -> Self { | ||
LatticeError::IoError(err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.