Provide blanket From impls for homogeneous collections
- 主要言語
- Rust
- スター
- 1.4k
- フォーク
- 162
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Hey!
First of all thanks for your work!
Could you imagine adding `From` impls for the `Array` and `Map` Value variants for homogeneous collections of elements that already are `Into`? This would improve the API ergonomics quite a bit in common (well, common for me...) cases. Coherence does not let me provide these impls in a different crate.
As a POC, have a look at [this playground](https://play.rust-lang.org/?gist=5b402cbce698f0eef661eb8045fdc8a1&version=stable&mode=release&edition=2015), which provides these impls for a simplified version of `Value`. Of course, those impls need to allocate a new `Vec`.
Now, they conflict with the existing `From>` and `From>` impls. Replacing them might not be opportune, since the existing impls do not allocate, which is an advantage. Othoh, I'd argue that the allocation happens anyways at the call sites, so that might not be a problem. What do you think? Specialization would help, of course :) But maybe there's another way around that in this case?
Anyways, thanks for reading. If you consider to do this, I'd be open to send a PR.
(e) I'd like to put up another argument for the "new" impls. Firstly, I went through the creates dependent on rmpv. I'd say it was inconclusive due to too few crates :) But many might depent on it transitively, e.g. my crate did not show up, although I'm using rpmv through the reexports in neovim-lib.
Now, what I wanted to say was that the "old" impl can easily be replicated. Say you have a `v: Vec` and want to avoid the alloction of the "new" impl, you could just use `Value::Array(v)` instead of `Value::from(v)`, so you're not locked into having a superflous allocation, if for some reason you're handling a `Vec` without having handled the "original" `Vec>` before.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず、Value Array と Map のバリアント、および既存の From> と From<(Value, Value)> の実装を確認します。提案されている blanket implementations と、リンク先の Rust playground の proof of concept を比較し、coherence とアロケーションのトレードオフに注目します。競合する変換動作の設計が解決されて初めて、issue は完了となります。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- rust
- 領域
- data
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100