mimewritable
mimewritable(mime, x)
Returns a boolean value indicating whether or not the object x
can be written as the given mime
type. (By default, this is determined automatically by the existence of the corresponding writemime
function for typeof(x)
.)
Examples
-
Check if an object can be written as a specific MIME type:
julia> mimewritable("text/plain", "Hello, world!") true
This example checks if the string
"Hello, world!"
can be written as the MIME type"text/plain"
. -
Check if an object of a custom type can be written as a MIME type:
julia> struct Person name::String age::Int end julia> person = Person("Alice", 25); julia> mimewritable("application/json", person) false
In this example, we define a custom type
Person
and check if an instance ofPerson
can be written as the MIME type"application/json"
. In this case, it returnsfalse
. - Use default behavior to determine if an object can be written:
julia> mimewritable("image/png", [1, 2, 3, 4, 5]) true
This example checks if the array
[1, 2, 3, 4, 5]
can be written as the MIME type"image/png"
. If a correspondingwritemime
function exists for the type ofx
, it will returntrue
.
Common mistake example:
julia> mimewritable("text/html", 42)
ERROR: ArgumentError: MIME type 'text/html' is not supported for values of type Int64
In this example, the MIME type "text/html"
is not supported for values of type Int64
. It's important to ensure that the specified MIME type is supported for the given object type to avoid such errors.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.