commit 5ec7d90886788a72e1bd3f78d25fa633d2215c63
parent 6ecee23721120cded7d27af5f627de3a7cd5f917
Author: Jojolepro <jojolepromain@gmail.com>
Date: Thu, 9 Aug 2018 09:47:57 -0400
Removed return ref
Diffstat:
2 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/src/lib.rs b/src/lib.rs
@@ -105,12 +105,12 @@ where
/// A lower bounded function is a function that is valid from [x..infinite[, or until it hits another function's start.
-struct LowerBoundedFunction<'a, B, O: 'a>
+struct LowerBoundedFunction<B, O>
where
B: PartialOrd,
{
/// The stored function f(x) = ???
- pub func: Box<Fn(B) -> &'a O>,
+ pub func: Box<Fn(B) -> O>,
/// The lower bound of the function.
pub lower: B,
}
@@ -126,25 +126,25 @@ where
/// f(0.5) = 5
/// f(1) = 10
/// f(70) = 10
-pub struct LowerPartialFunction<'a, B, O: 'a>
+pub struct LowerPartialFunction<B, O>
where
B: PartialOrd,
{
- funcs: Vec<LowerBoundedFunction<'a, B, O>>,
+ funcs: Vec<LowerBoundedFunction<B, O>>,
}
-impl<'a, B, O> LowerPartialFunction<'a, B, O>
+impl<B, O> LowerPartialFunction<B, O>
where
B: PartialOrd
{
/// Creates a new LowerPartialFunctionBuilder.
- pub fn new() -> LowerPartialFunctionBuilder<'a, B, O> {
+ pub fn new() -> LowerPartialFunctionBuilder<B, O> {
LowerPartialFunctionBuilder::new()
}
/// Evaluates the partial function.
/// Returns None if no function is defined for the searched invariable value (x).
- pub fn eval(&self, x: B) -> Option<&'a O> {
+ pub fn eval(&self, x: B) -> Option<O> {
let iter = self.funcs.iter().enumerate();
for (i, bounded) in iter {
let next = self.funcs.get(i + 1);
@@ -158,14 +158,14 @@ where
}
/// A builder to create an immutable PartialFunction.
-pub struct LowerPartialFunctionBuilder<'a, B, O: 'a>
+pub struct LowerPartialFunctionBuilder<B, O>
where
B: PartialOrd,
{
- funcs: Vec<LowerBoundedFunction<'a, B, O>>,
+ funcs: Vec<LowerBoundedFunction<B, O>>,
}
-impl<'a, B, O: 'a> LowerPartialFunctionBuilder<'a, B, O>
+impl<B, O> LowerPartialFunctionBuilder<B, O>
where
B: PartialOrd,
{
@@ -175,7 +175,7 @@ where
}
/// Adds a bounded function bounded between [lower,higher[ of function func.
- pub fn with<F: Fn(B) -> &'a O + 'static>(mut self, lower: B, func: F) -> Self {
+ pub fn with<F: Fn(B) -> O + 'static>(mut self, lower: B, func: F) -> Self {
debug_assert!(self.can_insert(&lower));
let f = LowerBoundedFunction {
func: Box::new(func),
@@ -191,7 +191,7 @@ where
}
/// Builds the PartialFunction from the functions added using with.
- pub fn build(mut self) -> LowerPartialFunction<'a, B, O> {
+ pub fn build(mut self) -> LowerPartialFunction<B, O> {
self.funcs.sort_by(|a, b| {
a.lower
.partial_cmp(&b.lower)
diff --git a/tests/tests.rs b/tests/tests.rs
@@ -84,35 +84,35 @@ mod tests {
#[test]
fn lower_partial_normal() {
let f = LowerPartialFunction::new()
- .with(0.0, |x| &1)
- .with(1.0, |x| &2)
+ .with(0.0, |x| 1)
+ .with(1.0, |x| 2)
.build();
assert_eq!(f.eval(-1.0),None);
- assert_eq!(f.eval(0.0),Some(&1));
- assert_eq!(f.eval(0.5),Some(&1));
- assert_eq!(f.eval(1.0),Some(&2));
- assert_eq!(f.eval(1000.0),Some(&2));
+ assert_eq!(f.eval(0.0),Some(1));
+ assert_eq!(f.eval(0.5),Some(1));
+ assert_eq!(f.eval(1.0),Some(2));
+ assert_eq!(f.eval(1000.0),Some(2));
}
#[test]
fn lower_partial_inverse_insert() {
let f = LowerPartialFunction::new()
- .with(1.0, |x| &2)
- .with(0.0, |x| &1)
+ .with(1.0, |x| 2)
+ .with(0.0, |x| 1)
.build();
assert_eq!(f.eval(-1.0),None);
- assert_eq!(f.eval(0.0),Some(&1));
- assert_eq!(f.eval(0.5),Some(&1));
- assert_eq!(f.eval(1.0),Some(&2));
- assert_eq!(f.eval(1000.0),Some(&2));
+ assert_eq!(f.eval(0.0),Some(1));
+ assert_eq!(f.eval(0.5),Some(1));
+ assert_eq!(f.eval(1.0),Some(2));
+ assert_eq!(f.eval(1000.0),Some(2));
}
#[test]
#[should_panic]
fn lower_partial_overlap() {
let f = LowerPartialFunction::new()
- .with(0.0, |x| &1)
- .with(0.0, |x| &2)
+ .with(0.0, |x| 1)
+ .with(0.0, |x| 2)
.build();
}
}