Attribute like `from` for `Box`ing large error variants

オープン
#424 コメント 2 件 リアクション 12 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rust
領域
devtools

調査の方向性

まず、thiserror の既存の #[from] の動作と、issue にリンクされている関連する thiserror_ext の Box ユーティリティを確認します。目的とする範囲として MyError の例を使用し、autobox アノテーションが内部エラーとその Box 形式の両方に対してどのように From 実装を生成すべきかを判断してから、生成された変換のカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

説明

Some recent clippy update warns for large enum error variants, and recommends boxing them. This is probably reasonable. It would be convenient if there was an annotation like from which would create the box itself rather than having to manually implement an increasingly common use case.

Looks like thiserror_ext has a related utility already: https://docs.rs/thiserror-ext/latest/thiserror_ext/derive.Box.html but could probably be cleaner. Something like

use thiserror::Error;

#[derive(Error, Debug)]
pub enum MyError {
    Small(#[from] small::Error),
    Big(#[from(autobox)] Box<big::Error>)
}

which would generate something like

use thiserror::Error;

#[derive(Error, Debug)]
pub enum MyError {
    Small(small::Error),
    Big(Box<big::Error>)
}

impl From<small::Error> for MyError {
    fn from(value: small::Error) -> Self {
        Self::Small(value)
    }
}

impl From<big::Error> for MyError {
    fn from(value: big::Error) -> Self {
        Self::Big(Box::new(value))
    }
}

Maybe with an impl From<Box<big::Error>> for MyError too, for completeness.

主要言語
Rust
スター
5.6k
フォーク
220
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dtolnay/thiserror のほかの issue

dtolnay/thiserror の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。