jupyter_protocol

Module media

Source
Expand description

Provides types and utilities for working with rich media content in Jupyter messages.

This module defines the Media and MediaType structures, which represent MIME bundles in Jupyter messages. These are used for rich content display in notebooks and other Jupyter frontends.

The main types in this module are:

  • Media: Represents a collection of media types.
  • MediaType: An enum representing various MIME types.

§Examples

Creating a media bundle with multiple types:

use jupyter_protocol::media::{Media, MediaType};

let media = Media::new(vec![
    MediaType::Plain("Hello, world!".to_string()),
    MediaType::Html("<h1>Hello, world!</h1>".to_string()),
]);

Finding the richest media type:

use jupyter_protocol::media::{Media, MediaType};

let media = Media::new(vec![
    MediaType::Plain("Hello, world!".to_string()),
    MediaType::Html("<h1>Hello, world!</h1>".to_string()),
    MediaType::Markdown("**Hello, world!**".to_string()),
]);

let richest = media.richest(|media_type| match media_type {
    MediaType::Html(_) => 3,
    MediaType::Markdown(_) => 2,
    MediaType::Plain(_) => 1,
    _ => 0,
});

assert!(matches!(richest, Some(MediaType::Html(_))));

Re-exports§

Modules§

Structs§

  • A Media is a collection of data associated with different Media types. It allows for the representation of rich content that can be displayed in multiple formats. These are found in the data field of a DisplayData and ExecuteResult messages/output types.

Enums§

  • An enumeration representing various Media types, otherwise known as MIME (Multipurpose Internet Mail Extensions) types. These types are used to indicate the nature of the data in a rich content message such as DisplayData, UpdateDisplayData, and ExecuteResult.

Functions§

Type Aliases§