# `Machete.StructLikeMatcher`
[🔗](https://github.com/mtrudel/machete/blob/main/lib/machete/matchers/struct_like_matcher.ex#L1)

Defines a matcher that matches structs only on a specified list of fields

# `t`

```elixir
@opaque t()
```

Describes an instance of this matcher

# `struct_like`

```elixir
@spec struct_like(
  struct(),
  Enum.t()
) :: t()
```

Matches structs only on a specified list of fields

Structs can be tricky to match because they have default values for fields which are not
specified at the point of creation. After creation these default values are otherwise
indistinguishable from user-specified ones, and often get in the way of effective matching. This
matcher provides a convenient way around this by allowing the user to describe both the type of
struct expected as well as a set of matchers for fields within the struct; only the fields
explicitly listed in the matcher are examined.

Fields can be specified via a map or keyword list in a manner identical to that of
`Kernel.struct/2`. Fields may be matched using any matcher, not just literal values.

Examples:
    iex> assert %URI{host: "example.com", path: "/abc"} ~> struct_like(URI, %{host: "example.com"})
    true

    iex> assert %URI{host: "example.com", path: "/abc"} ~> struct_like(URI, host: "example.com")
    true

    iex> assert %URI{host: "example.com", path: "/abc"} ~> struct_like(URI, host: string())
    true

    iex> assert %URI{host: "example.com", path: "/abc"} ~> struct_like(URI)
    true

    iex> refute %URI{host: "example.com"} ~> struct_like(URI, host: "example.com", path: "/abc")
    false

---

*Consult [api-reference.md](api-reference.md) for complete listing*
