dermesser / yup-oauth2

An oauth2 client implementation providing the Device, Installed, Service Account, and several more flows.
https://docs.rs/yup-oauth2/
Apache License 2.0
213 stars 114 forks source link

redirect_url to return String not &str #204

Closed k-bx closed 1 year ago

k-bx commented 1 year ago

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 commented 1 year ago

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

k-bx commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

I see, thanks for explaining!