Skip to content

Commit 00c097d

Browse files
authored
Remove 'static lifetime requirement for Plot.to_inline_html() (#115)
* remove 'static lifetime requirement * update changelog
1 parent d82d473 commit 00c097d

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [0.8.2] - 2022-11-xx
88
### Changed
9-
- Refactored the structure of the examples to make them more accessible, whilst adding more examples e.g. for `wasm`.
9+
- [[#113](https://github.com/igiagkiozis/plotly/pull/113)] Refactored the structure of the examples to make them more accessible, whilst adding more examples e.g. for `wasm`.
10+
- [[#115](https://github.com/igiagkiozis/plotly/pull/115)] Simplify the function signature of Plot.to_inline_html() so that it just takes `Option<&str>` as an argument.
1011

1112
## [0.8.1] - 2022-09-25
1213
### Added

plotly/src/plot.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ impl Plot {
323323
///
324324
/// To generate a full, standalone HTML string or file, use `Plot::to_html()` and `Plot::write_html()`,
325325
/// respectively.
326-
pub fn to_inline_html<T: Into<Option<&'static str>>>(&self, plot_div_id: T) -> String {
327-
let plot_div_id = plot_div_id.into();
326+
pub fn to_inline_html(&self, plot_div_id: Option<&str>) -> String {
328327
let plot_div_id = match plot_div_id {
329328
Some(id) => id.to_string(),
330329
None => Alphanumeric.sample_string(&mut thread_rng(), 20),
@@ -337,7 +336,7 @@ impl Plot {
337336

338337
let tmpl = JupyterNotebookPlotTemplate {
339338
plot: self,
340-
plot_div_id: plot_div_id.as_str(),
339+
plot_div_id: &plot_div_id,
341340
};
342341
tmpl.render().unwrap()
343342
}
@@ -486,18 +485,15 @@ mod tests {
486485
#[test]
487486
fn test_inline_plot() {
488487
let plot = create_test_plot();
489-
let inline_plot_data = plot.to_inline_html("replace_this_with_the_div_id");
488+
let inline_plot_data = plot.to_inline_html(Some("replace_this_with_the_div_id"));
490489
assert!(inline_plot_data.contains("replace_this_with_the_div_id"));
491-
println!("{}", inline_plot_data);
492-
let random_div_id = plot.to_inline_html(None);
493-
println!("{}", random_div_id);
490+
plot.to_inline_html(None);
494491
}
495492

496493
#[test]
497494
fn test_jupyter_notebook_plot() {
498495
let plot = create_test_plot();
499-
let inline_plot_data = plot.to_jupyter_notebook_html();
500-
println!("{}", inline_plot_data);
496+
plot.to_jupyter_notebook_html();
501497
}
502498

503499
#[test]

0 commit comments

Comments
 (0)