rust-cli / rust-cli/config-rs

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

Open
#43 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
3.2k
Forks
265
Avg merge
2h 42m
Merged PRs (30d)
4

Description

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).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the settings.get("redis_url") call used as an argument to redis::Client::open, then trace the configuration value conversion and caching path. The issue is done when requesting a converted configuration value in a context inferring &str behaves correctly, with regression coverage for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.