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!") trueThis 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) falseIn this example, we define a custom type
Personand check if an instance ofPersoncan 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]) trueThis example checks if the array
[1, 2, 3, 4, 5]can be written as the MIME type"image/png". If a correspondingwritemimefunction 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.