Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect_url to return String not &str #204

Closed
k-bx opened this issue Jun 2, 2023 · 4 comments
Closed

redirect_url to return String not &str #204

k-bx opened this issue Jun 2, 2023 · 4 comments

Comments

@k-bx
Copy link

k-bx commented Jun 2, 2023

I'm trying to implement something like:

    fn redirect_uri(&self) -> Option<&str> {
        let s: &'static str = &format!(
            "https://mywebsite.comapi/youtube/callback-{}",
            self.port
        );
        Some(s)
    }

but I can't, because of lifetimes. I see no good reason to make it return &str and not String, would be a nice change IMO.

@ggriffiniii
Copy link
Collaborator

Why not store the url as a member of your struct rather than computing it on each invocation of redirect_uri?

@k-bx
Copy link
Author

k-bx commented Jun 2, 2023

Would I need to make the whole struct be static then? I did make a set of global &'static strs that I query but it just seems overcomplicating the code a little.

@ggriffiniii
Copy link
Collaborator

No, the struct wouldn't need to be static.

fn redirect_uri(&self) -> Option<&str> indicates that the &str returned needs to live for at least as long as the &self reference. The struct would own a String that gets created using format! on construction and redirect_uri would just return &str that's a view into that String

@k-bx
Copy link
Author

k-bx commented Jun 2, 2023

I see, thanks for explaining!

@k-bx k-bx closed this as completed Jun 2, 2023
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

No branches or pull requests

2 participants