Skip to content

Remove ValueWithKey struct #109

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

Merged
merged 1 commit into from
May 13, 2019

Conversation

gnieto
Copy link
Contributor

@gnieto gnieto commented May 5, 2019

While using this library, I end up having lifetime issues with
Config::get. I've seen that current implementation forces the caller
to match key lifetime to the output of the function.

My use case is, under some circumstances, return a suffixed version of
the config key. Something similar to:

        if some_condition == true {
            let key_name = format!("{}_suffix", key);
            self.config.get(&key_name)
        } else {
	    self.config.get(key)
	}

This code is not compiling for me due to conflicting lifetimes. To avoid
this, I've started looking to the code and I've found that key needed
this lifetime because of ValueWithKey. The purpose of this struct
seems to be add more information to the errors that are returned to the
user.

To mitigate this lifetime coupling I've:

  • Mapped the error on Config::get to include the originating key of
    the current error
  • Remove all the code related with ValueWithKey

@mehcode
Copy link
Collaborator

mehcode commented May 9, 2019

🙇‍♂️ Thank you for your contribution. I apologize for the late response. Moving forward I want to re-think the design of config as a whole. See #111 for more details.


If you rebase it I'll merge it and put it out in a patch version. That type definitely needs to go.

While using this library, I end up having lifetime issues with
`Config::get`. I've seen that current implementation forces the calleer
to match `key` lifetime to the output of the function.

My use case is, under some circumstances, return a suffixed version of
the config key. Something similar to:

```
        if some_condition == true {
            let key_name = format!("{}_suffix", key);
            self.config.get(&key_name)
        } else {
	    self.config.get(key)
	}
```

This code is noy compiling for me due to conflicting lifetimes. To avoid
this, I've started looking to the code and  I've found that `key` needed
this lifetime because of `ValueWithKey`. The purpouse of this struct
seems to be add more information to the errors that are returned to the
user.

To mitigate this lifetime coupling I've:

- Mapped the error on `Config::get` to include the originating key of
  the current error
- Remove all the code related with `ValueWithKey`
@gnieto gnieto force-pushed the task/remove-value-with-key branch from 9dbd440 to 4cf99ea Compare May 9, 2019 17:28
@gnieto
Copy link
Contributor Author

gnieto commented May 9, 2019

@mehcode rebased!

I'll try to add some feedback during next week on #111 regarding how I plan to use this library, if it's useful. Once you are comfortable with a design, I'm willing to keep contributing.

For my use case, it has been very easy to integrate this library. I've written a custom Source and set up all the stack with very low effort. Thanks for you work!

@mehcode mehcode merged commit ad29f8f into rust-cli:master May 13, 2019
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.

2 participants