Skip to content

Could we remove the Copy requirement of ActualT type parameter in Matcher trait? #542

@chmnchiang

Description

@chmnchiang

In 471d4a2, the ActualT changed from an associated type to a type parameter. I think it is a good change, but is ActualT: Copy still required? In #323, there was some discussions about lifetime problems, but I don't think that is still valid now because the lifetime of the object being matched is not tied to the matcher anymore.

The comment in the code mentioned:

// `ActualT` requires `Copy` so that `actual` could be passed to `matches` and
// if it fails passed to `explain_match`. We can relax this constraint later by
// requiring only `Clone`.

But Copy in rust is generally considered cheap (if object is so large that memcpy is expensive, then the type probably shouldn't implement Copy in the first place), so there is no harm to take actual: &ActualT instead. If ActualT is Copy, the implementer can dereference it by themselves. This simplify a lot of lifetime problems when implementing custom matchers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions