Cannot call `show(io,MIME...`

I am surprised by the following

julia> struct Thing end

julia> x=Thing()
Thing()

julia> Base.show(io::IO,::MIME"text/plain",x::Thing)=print(io,"hello")

julia> show(stdout,MIME"text/plain",x)
ERROR: MethodError: no method matching show(::Base.TTY, ::Type{MIME{Symbol("text/plain")}}, ::Thing)
Closest candidates are:
  show(::IO, ::MIME{Symbol("text/plain")}, ::Thing) at REPL[3]:1
  show(::IO, ::MIME{Symbol("text/plain")}, ::Any) at multimedia.jl:47
  show(::IO, ::MIME{Symbol("text/csv")}, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/DelimitedFiles/src/DelimitedFiles.jl:828
  ...
Stacktrace:
 [1] top-level scope at REPL[4]:1

How to call the method of show I just defined?

1 Like

The function expects an instance of the MIME type, not the type itself.

julia> show(stdout,MIME"text/plain"(),x)
hello

Alternative:

julia> show(stdout,"text/plain",x)
hello
3 Likes

Thanks. I was confused about MIME strings