Skip to content

Remove static restriction for str ref#107

Closed
aleb wants to merge 2 commits intoplotly:devfrom
aleb:patch-1
Closed

Remove static restriction for str ref#107
aleb wants to merge 2 commits intoplotly:devfrom
aleb:patch-1

Conversation

@aleb
Copy link

@aleb aleb commented Oct 19, 2022

No description provided.

@aleb
Copy link
Author

aleb commented Oct 19, 2022

Currently this works fine:

map_plot.to_inline_html(Some("test"), 600)

And this not, but it should:

map_plot.to_inline_html(Some("test".to_string()), 600)

@kaihowl
Copy link
Contributor

kaihowl commented Oct 29, 2022

(You might need to target this to the dev branch in order to attract attention. See the following.) https://github.com/igiagkiozis/plotly/blob/c0ca69192c422862941617a72094e4e44fc9b67f/CONTRIBUTING.md?plain=1#L34-L35

@andrei-ng
Copy link
Collaborator

Came accross the same issue. Merging this would be useful.

@mfreeborn mfreeborn changed the base branch from master to dev November 1, 2022 10:49
@mfreeborn
Copy link
Contributor

I'll review this today hopefully, and add a test case so that we can make sure there isn't a regression in the future.

@andrei-ng
Copy link
Collaborator

andrei-ng commented Nov 1, 2022

@mfreeborn, @aleb , the patch is incorrect because it is missing lifetimes. I have a fix for the above. The function signature should be

pub fn to_inline_html<'a, T: Into<Option<&'a str>>>(&self, plot_div_id: T) -> String {

I build locally and the examples work fine with the above.

Should I fork and make a different PR or is it better we fix it in this already existing PR ?

@mfreeborn
Copy link
Contributor

mfreeborn commented Nov 1, 2022 via email

@mfreeborn
Copy link
Contributor

mfreeborn commented Nov 1, 2022

@mfreeborn, @aleb , the patch is incorrect because it is missing lifetimes. I have a fix for the above. The function signature should be

pub fn to_inline_html<'a, T: Into<Option<&'a str>>>(&self, plot_div_id: T) -> String {

I build locally and the examples work fine with the above.

Should I fork and make a different PR or is it better we fix it in this already existing PR ?

Hang on a sec, I've just read this properly and I believe what we are looking for is:

pub fn to_inline_html<T: Option<AsRef<str>>(&self, plot_div_id: T) -> String {
    let plot_div_id = plot_div_id.into();
    let plot_div_id = match plot_div_id {
        Some(id) => id.as_ref(),
        None => Alphanumeric.sample_string(&mut thread_rng(), 20),
    };
    self.render_inline(plot_div_id)
}

EDIT: updated what I think should work as an implementation.

@aleb
Copy link
Author

aleb commented Nov 1, 2022

Please create a separate PR, one that is made for the dev branch...

I'm not sure how the lifetime addition is better, if you ask me..

many thanks & let me close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants