From 4cf99ea2a2a84b8a25822a26404af61f29ba87b5 Mon Sep 17 00:00:00 2001 From: Guillem Nieto Date: Sun, 5 May 2019 23:53:30 +0200 Subject: Remove ValueWithKey struct 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` --- src/ser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ser.rs') diff --git a/src/ser.rs b/src/ser.rs index 32b99ac..b4c1628 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use std::mem; use error::*; -use value::{Value, ValueKind, ValueWithKey}; +use value::{Value, ValueKind}; use Config; #[derive(Default, Debug)] -- cgit v1.2.3