Skip to content

Commit eeb0df8

Browse files
authored
Merge pull request #5 from mshrtsr/develop
version 0.3.0
2 parents de63cb3 + 7e604d3 commit eeb0df8

File tree

4 files changed

+23
-75
lines changed

4 files changed

+23
-75
lines changed

Cargo.toml

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
[package]
22
name = "fitting"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
authors = ["Masaharu TASHIRO <[email protected]>"]
55
edition = "2018"
6-
76
# A short blurb about the package. This is not rendered in any format when
87
# uploaded to crates.io (aka this is not markdown).
98
description = "Pure Rust curve fitting library"
10-
119
# These URLs point to more information about the package. These are
1210
# intended to be webviews of the relevant data, not necessarily compatible
1311
# with VCS tools and the like.
1412
documentation = "https://docs.rs/fitting/"
1513
homepage = "https://crates.io/crates/fitting"
1614
repository = "https://github.com/mshrtsr/fitting-rs"
17-
1815
# This points to a file under the package root (relative to this `Cargo.toml`).
1916
# The contents of this file are stored and indexed in the registry.
2017
# crates.io will render this file and place the result on the crate's page.
2118
readme = "README.md"
22-
2319
# This is a list of up to five keywords that describe this crate. Keywords
2420
# are searchable on crates.io, and you may choose any words that would
2521
# help someone find this crate.
26-
keywords = ["fitting","statistics","probability","distribution","math"]
27-
22+
keywords = ["fitting", "statistics", "probability", "distribution", "math"]
2823
# This is a list of up to five categories where this crate would fit.
2924
# Categories are a fixed list available at crates.io/category_slugs, and
3025
# they must match exactly.
3126
categories = ["science"]
32-
3327
# This is an SPDX 2.1 license expression for this package. Currently
3428
# crates.io will validate the license provided against a whitelist of
3529
# known license and exception identifiers from the SPDX license list
@@ -39,23 +33,19 @@ categories = ["science"]
3933
# is deprecated. Instead, use a license expression with AND and OR
4034
# operators to get more explicit semantics.
4135
license = "MIT"
42-
4336
# If a package is using a nonstandard license, then this key may be specified in
4437
# lieu of the above key and must point to a file relative to this manifest
4538
# (similar to the readme key).
4639
# license-file = "..."
47-
4840
exclude = ["/.github/*", "./circleci/*", "/.travis.yml"]
4941

5042
[badges]
5143
circle-ci = { repository = "mshrtsr/fitting-rs", branch = "master" }
5244
travis-ci = { repository = "mshrtsr/fitting-rs", branch = "master" }
53-
5445
# Codecov: `repository` is required. `branch` is optional; default is `master`
5546
# `service` is optional; valid values are `github` (default), `bitbucket`, and
5647
# `gitlab`.
5748
codecov = { repository = "mshrtsr/fitting-rs", branch = "master", service = "github" }
58-
5949
# Maintenance: `status` is required. Available options are:
6050
# - `actively-developed`: New features are being added and bugs are being fixed.
6151
# - `passively-maintained`: There are no plans for new features, but the maintainer intends to
@@ -74,8 +64,7 @@ codecov = { repository = "mshrtsr/fitting-rs", branch = "master", service = "git
7464
maintenance = { status = "actively-developed" }
7565

7666
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77-
7867
[dependencies]
7968
ndarray = { version = "0.13.0", features = ["approx"] }
8069
approx = "0.3.2"
81-
failure = "0.1.6"
70+
thiserror = "1.0.17"

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ Curve fitting library for Rust
1111

1212
## Updates
1313

14+
### 0.3.0
15+
16+
- Migrate from the `failure` crate to `thiserror`.
17+
- Refactor some tests.
18+
1419
### 0.2.1
1520

1621
- Error handing changed. Some functions returns Result instead of Option.

src/error.rs

+8-54
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,14 @@
1-
use failure::{Backtrace, Context, Fail};
2-
use std::fmt;
3-
use std::fmt::Display;
1+
use thiserror::Error;
42

5-
#[derive(Debug)]
6-
pub struct Error {
7-
inner: Context<ErrorKind>,
8-
}
9-
10-
#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
11-
pub enum ErrorKind {
12-
#[fail(display = "None error")]
3+
//#[derive(Copy, Clone, Eq, PartialEq, Debug, Fail)]
4+
#[derive(Error, Debug, Eq, PartialEq)]
5+
pub enum Error {
6+
#[error("None error")]
137
Optional,
14-
#[fail(display = "Line Algebra error: Equations have no solutions")]
8+
#[error("Line Algebra error: Equations have no solutions")]
159
LinalgSolveNoSolutions,
16-
#[fail(display = "Line Algebra error: Equations have infinite solutions")]
10+
#[error("Line Algebra error: Equations have infinite solutions")]
1711
LinalgSolveInfSolutions,
18-
#[fail(display = "Fitting error")]
12+
#[error("Fitting error")]
1913
Fitting,
2014
}
21-
22-
impl Fail for Error {
23-
fn cause(&self) -> Option<&dyn Fail> {
24-
self.inner.cause()
25-
}
26-
27-
fn backtrace(&self) -> Option<&Backtrace> {
28-
self.inner.backtrace()
29-
}
30-
}
31-
32-
impl Display for Error {
33-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34-
Display::fmt(&self.inner, f)
35-
}
36-
}
37-
38-
impl Error {
39-
pub fn new(inner: Context<ErrorKind>) -> Error {
40-
Error { inner }
41-
}
42-
43-
pub fn kind(&self) -> &ErrorKind {
44-
self.inner.get_context()
45-
}
46-
}
47-
48-
impl From<ErrorKind> for Error {
49-
fn from(kind: ErrorKind) -> Error {
50-
Error {
51-
inner: Context::new(kind),
52-
}
53-
}
54-
}
55-
56-
impl From<Context<ErrorKind>> for Error {
57-
fn from(inner: Context<ErrorKind>) -> Error {
58-
Error { inner }
59-
}
60-
}

src/linalg.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::error::{Error, ErrorKind};
1+
use crate::error::Error;
22
use approx::{abs_diff_eq, abs_diff_ne};
33
use ndarray::{s, Array1, Array2, Axis};
44

@@ -79,12 +79,12 @@ pub fn solve(a: Array2<f64>, b: Array1<f64>) -> Result<Array1<f64>, Error> {
7979

8080
// no solutions
8181
if rank_coef != rank_aug {
82-
return Err(Error::from(ErrorKind::LinalgSolveNoSolutions));
82+
return Err(Error::LinalgSolveNoSolutions);
8383
}
8484

8585
// infinite solutions
8686
if rank_coef != a.ncols() {
87-
return Err(Error::from(ErrorKind::LinalgSolveInfSolutions));
87+
return Err(Error::LinalgSolveInfSolutions);
8888
}
8989

9090
// backward substitution
@@ -170,7 +170,7 @@ mod tests {
170170
let a = array![[2., 1., -3., -2.], [2., -1., -1., 3.], [1., -1., -2., 2.]];
171171
let b = array![4., 1., -3.];
172172
let err = solve(a, b).unwrap_err(); //panic
173-
assert!(err.kind() == &ErrorKind::LinalgSolveInfSolutions);
173+
assert_eq!(err, Error::LinalgSolveInfSolutions);
174174
}
175175

176176
#[test]
@@ -186,7 +186,7 @@ mod tests {
186186
];
187187
let b = array![2., -6. / 5., -1., 1.];
188188
let err = solve(a, b).unwrap_err(); //panic
189-
assert!(err.kind() == &ErrorKind::LinalgSolveInfSolutions);
189+
assert_eq!(err, Error::LinalgSolveInfSolutions);
190190
}
191191

192192
#[test]
@@ -197,7 +197,7 @@ mod tests {
197197
let a = array![[-2., 3.], [4., 1.], [1., -3.],];
198198
let b = array![1., 5., -1.];
199199
let err = solve(a, b).unwrap_err(); //panic
200-
assert!(err.kind() == &ErrorKind::LinalgSolveNoSolutions);
200+
assert_eq!(err, Error::LinalgSolveNoSolutions);
201201
}
202202

203203
#[test]
@@ -208,6 +208,6 @@ mod tests {
208208
let a = array![[1., 3., -2.], [-1., 2., -3.], [2., -1., 3.],];
209209
let b = array![2., -2., 3.];
210210
let err = solve(a, b).unwrap_err(); //panic
211-
assert!(err.kind() == &ErrorKind::LinalgSolveNoSolutions);
211+
assert_eq!(err, Error::LinalgSolveNoSolutions);
212212
}
213213
}

0 commit comments

Comments
 (0)