Implementing the Inspect protocol?

Are there any good resources for learning how to implement the Inspect protocol and use the Inspect.Algebra module?

Is it possible to use the built-in implementation of inspect for structs, inside of your own implementation? I noticed you get into an infinite loop when trying to do so.

Thanks!

I think the best way is to look at how built-in implementations looks like. Say you want to use Version inspect implementation, that’s the Inspect.Version module:

iex> open Inspect.Version

I noticed you get into an infinite loop when trying to do so.

You’re probably calling inspect directly inside your function, call e.g.: Inspect.Version.inspect/2 instead.

2 Likes

Looks like that worked! I was able to call Inspect.Any.inspect/2 and it outputted the standard formatting for inspecting a struct.

Thanks!

3 Likes

Oh my, just discovered open/1 in iex. How did I not know about this. Thanks @wojtekmach!! :heart_eyes:

2 Likes