commit f6391a3d79faf59e28419d5cf768bfdb8157583d
parent dbc83899c2dfdaea44b5a7f100ac3568c2820bc9
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Sat, 6 Apr 2024 00:24:48 -0400
tweak mutable references (not working tho)
Diffstat:
2 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/rust/src/main.rs b/rust/src/main.rs
@@ -1,16 +1,26 @@
use rand_core::SeedableRng;
-use rand_distr::{Distribution, Normal};
use rand_pcg::Pcg64Mcg;
+use rand_distr::{Normal, Distribution};
// use rand::thread_rng;
// use rand::prelude::*
+fn model(rng: &mut Pcg64Mcg) -> f64 {
+ let x = 1.0;
+ let normal = Normal::new(2.0, 3.0).unwrap();
+ let v = normal.sample(&mut rng);
+ v * x
+}
+
fn main() {
println!("Hello, world!");
let mut rng = Pcg64Mcg::seed_from_u64(1);
// mean 2, standard deviation 3
- let normal = Normal::new(2.0, 3.0).unwrap();
- let v = normal.sample(&mut rng);
- println!("{} is from a N(2, 9) distribution", v)
+ let v = model(&mut rng);
+ println!("{} is from a N(2, 9) distribution", v);
+ let z = model(&mut rng);
+ println!("{} is from a N(2, 9) distribution", z);
}
+
+
diff --git a/rust/tmp.txt b/rust/tmp.txt
@@ -0,0 +1,40 @@
+
+
+ Compiling squiggle_rust v0.1.0 (/home/nuno/Documents/core/software/fresh/time-to-botec/rust)
+warning: variable does not need to be mutable
+ --> src/main.rs:18:9
+ |
+18 | let mut rng = Pcg64Mcg::seed_from_u64(1);
+ | ----^^^
+ | |
+ | help: remove this `mut`
+ |
+ = note: `#[warn(unused_mut)]` on by default
+
+error[E0382]: use of moved value: `rng`
+ --> src/main.rs:22:19
+ |
+18 | let mut rng = Pcg64Mcg::seed_from_u64(1);
+ | ------- move occurs because `rng` has type `Mcg128Xsl64`, which does not implement the `Copy` trait
+19 | // mean 2, standard deviation 3
+20 | let v = model(rng);
+ | --- value moved here
+21 | println!("{} is from a N(2, 9) distribution", v);
+22 | let z = model(rng);
+ | ^^^ value used here after move
+ |
+note: consider changing this parameter type in function `model` to borrow instead if owning the value isn't necessary
+ --> src/main.rs:8:19
+ |
+8 | fn model(mut rng: Pcg64Mcg) -> f64 {
+ | ----- ^^^^^^^^ this parameter takes ownership of the value
+ | |
+ | in this function
+help: consider cloning the value if the performance cost is acceptable
+ |
+20 | let v = model(rng.clone());
+ | ++++++++
+
+For more information about this error, try `rustc --explain E0382`.
+warning: `squiggle_rust` (bin "squiggle_rust") generated 1 warning
+error: could not compile `squiggle_rust` (bin "squiggle_rust") due to 1 previous error; 1 warning emitted