I’m doing some statistical things using the statrs crate. It implements a number of distribution functions and my input can be one of them, and not always the same.

I would like to have something that in pseudo-code looks like this:

```
let curve = create_curve (from parameters);
curve.sample(some point);
curve.pdf(some point);
```

Unfortunately, the two functions I need, sample() and pdf() are implemented in two different traits (Distribution and Continuous) and rust can’t return multiple traits. So I’ve been wrecking my brain trying to figure out a way to do this kind of abstract handling. It gets a bit more tricky as both the sample() and the pdf() are inside their own seperate functions because I do additional processing, so I also need to pass the curve into them.

My (non-functioning) code is like this:

```
extern crate statrs;
extern crate rand;
use statrs::distribution::{Beta, LogNormal, Continuous};
use statrs::statistics::Variance;
use rand::distributions::Distribution;
pub fn main(dist: &str, min: f64, max: f64) -> f64 {
let curve = create_curve();
curve_value(&curve, min, max);
}
fn create_curve(dist: &str) -> impl Distribution<f64> + Continuous<f64, f64> {
match dist {
"lognorm" => lognorm_from_pert(),
_ => beta_from_pert()
}
}
fn beta_from_pert() -> impl Distribution<f64> + Continuous<f64, f64> {
Beta::new(1.5, 0.5).unwrap()
}
fn lognorm_from_pert() -> impl Distribution<f64> + Continuous<f64, f64> {
LogNormal::new(1.5, 0.5).unwrap()
}
fn curve_value(curve: &impl Distribution<f64>, min: f64, max: f64) -> f64 {
curve.sample(&mut rand::thread_rng()) * ( max - min) + min
}
```

The basic **idea** is that I want to have a code that goes “ok, here is a curve, it has these traits and I’ll use them without worrying which type of curve it is”. The exact thing that traits should do, but the multiple traits thing is making it impossible.