Skip to content

has_length on Map does not need PartialEq constraint on the value #18

@woshilapin

Description

@woshilapin

has_length is constrained by V: PartialEq + Debug but the fact that the value has PartialEq constraint is useless to count entries in the map. It is actually a problem in the following example.

struct Object(u32);

let mut map = HashMap::new();
map.insert(0, Object(42));

assert_that!(map).has_length(1);

This code produces the following error

error[E0599]: no method named `has_length` found for type `spectral::Spec<'_, std::collections::HashMap<{integer}, tests::from_gtfs_into_model::Object>>` in t
he current scope
   --> gtfs/src/lib.rs:132:27
    |
132 |         assert_that!(map).has_length(1);
    |                           ^^^^^^^^^^ method not found in `spectral::Spec<'_, std::collections::HashMap<{integer}, tests::from_gtfs_into_model::Object>>`
    |
    = note: the method `has_length` exists but the following trait bounds were not satisfied:
            `spectral::Spec<'_, std::collections::HashMap<{integer}, tests::from_gtfs_into_model::Object>> : spectral::hashmap::HashMapAssertions<_, _>`

error: aborting due to previous error

A simple fix is the implementation of PartialEq on Object but that's not really on option for some objects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions