diff --git a/examples/examples/montecarlo/integraal.rs b/examples/examples/montecarlo/integraal.rs index f0bf5af..1020833 100644 --- a/examples/examples/montecarlo/integraal.rs +++ b/examples/examples/montecarlo/integraal.rs @@ -11,8 +11,10 @@ fn main() { let method = ComputeMethod::MonteCarlo { n_sample: 100 }; // build the integral - let mut integral = Integraal::default(); - integral.domain(domain).function(function).method(method); + let mut integral = Integraal::default() + .domain(domain) + .function(function) + .method(method); // compute & print let res: f64 = integral.compute().unwrap(); diff --git a/examples/examples/rectangle/integraal.rs b/examples/examples/rectangle/integraal.rs index fa22bee..3056384 100644 --- a/examples/examples/rectangle/integraal.rs +++ b/examples/examples/rectangle/integraal.rs @@ -11,8 +11,10 @@ fn main() { let method = ComputeMethod::RectangleLeft; // build the integral - let mut integral = Integraal::default(); - integral.domain(domain).function(function).method(method); + let mut integral = Integraal::default() + .domain(domain) + .function(function) + .method(method); // compute & print let res: f64 = integral.compute().unwrap(); diff --git a/examples/examples/trapezoid/integraal.rs b/examples/examples/trapezoid/integraal.rs index 32fbe44..1281367 100644 --- a/examples/examples/trapezoid/integraal.rs +++ b/examples/examples/trapezoid/integraal.rs @@ -11,8 +11,10 @@ fn main() { let method = ComputeMethod::Trapezoid; // build the integral - let mut integral = Integraal::default(); - integral.domain(domain).function(function).method(method); + let mut integral = Integraal::default() + .domain(domain) + .function(function) + .method(method); // compute & print let res: f64 = integral.compute().unwrap(); diff --git a/integraal/src/structure/definitions.rs b/integraal/src/structure/definitions.rs index d214bc6..075582d 100644 --- a/integraal/src/structure/definitions.rs +++ b/integraal/src/structure/definitions.rs @@ -52,8 +52,10 @@ pub enum IntegraalError { /// let method = ComputeMethod::Trapezoid; /// /// // build the integral & compute it -/// let mut integral = Integraal::default(); -/// integral.domain(domain).function(function).method(method); +/// let mut integral = Integraal::default() +/// .domain(domain) +/// .function(function) +/// .method(method); /// assert!(integral.compute().is_ok()) /// # } /// ``` diff --git a/integraal/src/structure/implementations.rs b/integraal/src/structure/implementations.rs index 9e6de29..b6c5b67 100644 --- a/integraal/src/structure/implementations.rs +++ b/integraal/src/structure/implementations.rs @@ -11,19 +11,22 @@ use std::ops::Deref; impl<'a, X: Scalar> Integraal<'a, X> { /// Set the domain descriptor. - pub fn domain(&mut self, domain_descriptor: DomainDescriptor<'a, X>) -> &mut Self { + #[must_use = "unused builder struct - please remove this call"] + pub fn domain(mut self, domain_descriptor: DomainDescriptor<'a, X>) -> Self { self.domain = Some(domain_descriptor); self } /// Set the function descriptor. - pub fn function(&mut self, function_descriptor: FunctionDescriptor) -> &mut Self { + #[must_use = "unused builder struct - please remove this call"] + pub fn function(mut self, function_descriptor: FunctionDescriptor) -> Self { self.function = Some(function_descriptor); self } /// Set the numerical integration method. - pub fn method(&mut self, compute_method: ComputeMethod) -> &mut Self { + #[must_use = "unused builder struct - please remove this call"] + pub fn method(mut self, compute_method: ComputeMethod) -> Self { self.method = Some(compute_method); self } diff --git a/integraal/src/structure/tests.rs b/integraal/src/structure/tests.rs index b181f67..32860b4 100644 --- a/integraal/src/structure/tests.rs +++ b/integraal/src/structure/tests.rs @@ -24,8 +24,7 @@ macro_rules! generate_sample_descriptors { macro_rules! generate_missing { ($a: ident, $b: ident) => { - let mut integral: Integraal<'_, f64> = Integraal::default(); - integral.$a($a).$b($b); + let mut integral: Integraal<'_, f64> = Integraal::default().$a($a).$b($b); assert_eq!( integral.compute(), Err(IntegraalError::MissingParameters( @@ -53,8 +52,7 @@ fn missing_parameters() { generate_missing!(function, domain); // missing all but one - let mut integral: Integraal<'_, f64> = Integraal::default(); - integral.method(method); + let mut integral: Integraal<'_, f64> = Integraal::default().method(method); assert_eq!( integral.compute(), Err(IntegraalError::MissingParameters( @@ -70,8 +68,10 @@ fn inconsistent_parameters() { let domain = vec![0.0, 0.1, 0.2, 0.3, 0.4]; // missing the last x value let domain = DomainDescriptor::Explicit(&domain); - let mut integral = Integraal::default(); - integral.method(method).function(function).domain(domain); + let mut integral = Integraal::default() + .method(method) + .function(function) + .domain(domain); assert_eq!( integral.compute(), Err(IntegraalError::InconsistentParameters( @@ -87,8 +87,10 @@ fn inconsistent_parameters() { }; let function = FunctionDescriptor::Values(vec![1., 1., 1., 1., 1., 1.]); - let mut integral = Integraal::default(); - integral.method(method).function(function).domain(domain); + let mut integral = Integraal::default() + .method(method) + .function(function) + .domain(domain); assert_eq!( integral.compute(), Err(IntegraalError::InconsistentParameters( @@ -136,12 +138,11 @@ macro_rules! generate_test { let functiond = $fnd; let domaind = $dmd; let computem = $met; - let mut integraal = Integraal::default(); - let res = integraal + let mut integraal = Integraal::default() .function(functiond) .domain(domaind) - .method(computem) - .compute(); + .method(computem); + let res = integraal.compute(); assert!(res.is_ok()); assert!( almost_equal!(res.unwrap(), 2.0, $tol), @@ -157,8 +158,7 @@ macro_rules! generate_test { let functiond = $fnd; let domaind = $dmd; let computem = $met; - let mut integraal = Integraal::default(); - integraal + let integraal = Integraal::default() .function(functiond) .domain(domaind) .method(computem); @@ -343,7 +343,7 @@ fn B_Closure_Explicit_Rectangle() { .collect(); let domaind = DomainDescriptor::Explicit(&domain); let computem = ComputeMethod::RectangleLeft; - let mut integraal = Integraal::default(); + let integraal = Integraal::default(); let res = integraal .function(functiond) .domain(domaind)