如何在长生不老药中正确断言结构类型

how to correctly assert struct type in elixir

我知道你可以像这样断言类型结构(尽管它更像是一个模块断言):

assert foo.__struct__ == Foo

但是有没有更优雅的方法来做到这一点?类似于:

assert type(foo) == %Foo{}

您可以使用=和模式匹配:

assert %Foo{} = foo