diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-09-18 20:39:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 20:39:47 +0200 |
commit | f44522eac9c9f13835d4df62135bb5728a000239 (patch) | |
tree | 1c7eb59691e1ffbf8b1620bd34227fa25033ff78 /cli/ops/random.rs | |
parent | 4fcfff0393a90bef6313df2c8895cd285da29440 (diff) |
refactor: move fields from CliState to OpState (#7558)
- move rng to OpState
- move GlobalTimer to OpState
- move Metrics to OpState
Diffstat (limited to 'cli/ops/random.rs')
-rw-r--r-- | cli/ops/random.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/cli/ops/random.rs b/cli/ops/random.rs index 2458bc453..84e38d105 100644 --- a/cli/ops/random.rs +++ b/cli/ops/random.rs @@ -3,6 +3,7 @@ use deno_core::error::AnyError; use deno_core::OpState; use deno_core::ZeroCopyBuf; +use rand::rngs::StdRng; use rand::thread_rng; use rand::Rng; use serde_json::Value; @@ -17,9 +18,9 @@ fn op_get_random_values( zero_copy: &mut [ZeroCopyBuf], ) -> Result<Value, AnyError> { assert_eq!(zero_copy.len(), 1); - let cli_state = super::cli_state(state); - if let Some(seeded_rng) = &cli_state.seeded_rng { - seeded_rng.borrow_mut().fill(&mut *zero_copy[0]); + let maybe_seeded_rng = state.try_borrow_mut::<StdRng>(); + if let Some(seeded_rng) = maybe_seeded_rng { + seeded_rng.fill(&mut *zero_copy[0]); } else { let mut rng = thread_rng(); rng.fill(&mut *zero_copy[0]); |