jupyter_protocol/
lib.rs

1//! # Jupyter Protocol
2//!
3//! This crate provides a complete implementation of the Jupyter messaging protocol,
4//! as specified in the [Jupyter Client documentation](https://jupyter-client.readthedocs.io/en/latest/messaging.html).
5//!
6//! It includes types and structures for all Jupyter message types, as well as
7//! utilities for working with Jupyter kernels and clients.
8//!
9//! ## Main Components
10//!
11//! - [`JupyterMessage`]: The main message type, encompassing all Jupyter protocol messages.
12//! - [`JupyterMessageContent`]: An enum representing the various content types for Jupyter messages.
13//! - [`Media`]: Represents rich media content (MIME bundles) in Jupyter messages.
14//! - [`ConnectionInfo`]: Contains information needed to connect to a Jupyter kernel.
15//!
16//! ## Usage
17//!
18//! Here's a basic example of creating and working with Jupyter messages:
19//!
20//! ```rust
21//! use jupyter_protocol::{JupyterMessage, ExecuteRequest, JupyterMessageContent};
22//!
23//! // Create an execute request
24//! let execute_request = ExecuteRequest::new("print('Hello, world!')".to_string());
25//!
26//! // Convert it to a JupyterMessage
27//! let message: JupyterMessage = execute_request.into();
28//!
29//! // You can then send this message using your preferred transport layer
30//!
31//! // When receiving messages, you can match on the content type:
32//! match message.content {
33//!     JupyterMessageContent::ExecuteRequest(req) => {
34//!         println!("Received execute request with code: {}", req.code);
35//!     },
36//!     _ => println!("Received other message type"),
37//! }
38//! ```
39//!
40//! For more detailed examples and usage information, see the documentation for
41//! individual modules and types.
42pub mod messaging;
43pub use messaging::*;
44
45pub mod connection_info;
46pub use connection_info::{ConnectionInfo, Transport};
47
48mod time;
49
50mod execution_count;
51pub use execution_count::*;
52
53mod kernelspec;
54pub use kernelspec::*;
55
56pub mod media;
57pub use media::*;
58
59use async_trait::async_trait;
60use futures::{Sink, Stream};
61
62#[async_trait]
63pub trait JupyterConnection:
64    Sink<JupyterMessage> + Stream<Item = Result<JupyterMessage, anyhow::Error>>
65{
66}