Skip to content

Commit 22764e9

Browse files
Copilotlloydmeta
andcommitted
Add diagnostic::on_unimplemented attributes to Transmogrifier and ByNameFieldPlucker traits
Co-authored-by: lloydmeta <914805+lloydmeta@users.noreply.github.com>
1 parent d04eb53 commit 22764e9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎core/src/labelled.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ where
586586
}
587587

588588
/// Trait for plucking out a `Field` from a type by type-level `TargetKey`.
589+
#[diagnostic::on_unimplemented(
590+
message = "Cannot find field with key `{TargetKey}` in `{Self}`",
591+
label = "Field not found",
592+
note = "The source type does not contain a field with the target key.",
593+
note = "Make sure the field name exists in the source struct and matches exactly."
594+
)]
589595
pub trait ByNameFieldPlucker<TargetKey, Index> {
590596
type TargetValue;
591597
type Remainder;
@@ -752,6 +758,13 @@ where
752758
///
753759
/// Credit:
754760
/// 1. Haskell "transmogrify" Github repo: <https://github.com/ivan-m/transmogrify>
761+
#[diagnostic::on_unimplemented(
762+
message = "Cannot transmogrify `{Self}` into `{Target}`",
763+
label = "Cannot convert this type into the target type",
764+
note = "Transmogrify requires that the source and target types have compatible structures.",
765+
note = "The source type must have all the fields needed for the target type, possibly in a different order or nested structure.",
766+
note = "Check that field names match and types are compatible between the source and target."
767+
)]
755768
pub trait Transmogrifier<Target, TransmogrifyIndexIndices> {
756769
/// Consume this current object and return an object of the Target type.
757770
///

0 commit comments

Comments
 (0)