Skip to content

When requesting a configuration property in a context that infers &str, the method fails #43

Open
@mehcode

Description

@mehcode
let redis_client = redis::Client::open(settings.get("redis_url").unwrap()).unwrap();

invalid type: string "...", expected a borrowed string


This is because of type conversions. We must return a String because there may have been a type conversion.
I can see this fixed in two ways:

  • Fix this by allowing to get out a &str if the underlying value is stored as a String. I don't like this because it'd only work sometimes.
  • Fix this by storing the type conversion in the cache when the value is requested. This makes a kind of sense because I believe we can optimize for users requesting the same type of value over-and-over-again. I was already going to add an initial "guess" that losslessly converts your incoming config value on the assumption that if you give us a "1" through an environment variable you probably meant 1.

As a side note I'm starting a medium-large project in Rust (finally) and am using this crate. Hopefully will find a ton of usage issues and annoyances (like this).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions