Skip to content

Commit 9d431bd

Browse files
committed
remove rand dependency on getrandom package/feature
- we use rand internally to create random names for div's and for file names, for that reason highly performant crypto and/or efficinet entropy generators are not a priority. Using rand with minimal features and no `getrandom` simplifies usage for downstream users as they don't need the custom WASM rustc flags for `getrandom` and `wasm_js` feature Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent 773343a commit 9d431bd

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

.cargo/config.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

plotly/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ serde = { version = "1.0", features = ["derive"] }
6060
serde_json = "1.0"
6161
serde_repr = "0.1"
6262
serde_with = ">=2, <4"
63-
rand = "0.9"
63+
rand = { version = "0.9", default-features = false, features = [
64+
"small_rng",
65+
"alloc",
66+
] }
6467

6568
[target.'cfg(target_arch = "wasm32")'.dependencies]
66-
getrandom = { version = "0.3", features = ["wasm_js"] }
6769
wasm-bindgen-futures = { version = "0.4" }
6870
wasm-bindgen = { version = "0.2" }
6971
serde-wasm-bindgen = { version = "0.6.3" }

plotly/src/plot.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use plotly_kaleido::ImageFormat;
99
use plotly_static::ImageFormat;
1010
use rand::{
1111
distr::{Alphanumeric, SampleString},
12-
rng,
12+
rngs::SmallRng,
13+
SeedableRng,
1314
};
1415
use serde::Serialize;
1516

@@ -265,12 +266,11 @@ impl Plot {
265266
#[cfg(all(not(target_family = "wasm"), not(target_os = "android")))]
266267
pub fn show(&self) {
267268
use std::env;
268-
269269
let rendered = self.render();
270270

271271
// Set up the temp file with a unique filename.
272272
let mut temp = env::temp_dir();
273-
let mut plot_name = Alphanumeric.sample_string(&mut rng(), 22);
273+
let mut plot_name = Alphanumeric.sample_string(&mut SmallRng::seed_from_u64(42), 22);
274274
plot_name.push_str(".html");
275275
plot_name = format!("plotly_{plot_name}");
276276
temp.push(plot_name);
@@ -313,7 +313,7 @@ impl Plot {
313313

314314
// Set up the temp file with a unique filename.
315315
let mut temp = env::temp_dir();
316-
let mut plot_name = Alphanumeric.sample_string(&mut rng(), 22);
316+
let mut plot_name = Alphanumeric.sample_string(&mut SmallRng::seed_from_u64(42), 22);
317317
plot_name.push_str(".html");
318318
plot_name = format!("plotly_{plot_name}");
319319
temp.push(plot_name);
@@ -371,13 +371,13 @@ impl Plot {
371371
pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String {
372372
let plot_div_id = match plot_div_id {
373373
Some(id) => id.to_string(),
374-
None => Alphanumeric.sample_string(&mut rng(), 20),
374+
None => Alphanumeric.sample_string(&mut SmallRng::seed_from_u64(42), 20),
375375
};
376376
self.render_inline(&plot_div_id)
377377
}
378378

379379
fn to_jupyter_notebook_html(&self) -> String {
380-
let plot_div_id = Alphanumeric.sample_string(&mut rng(), 20);
380+
let plot_div_id = Alphanumeric.sample_string(&mut SmallRng::seed_from_u64(42), 20);
381381

382382
let tmpl = JupyterNotebookPlotTemplate {
383383
plot: self,

0 commit comments

Comments
 (0)