pub struct StreamContent {
pub name: Stdio,
pub text: String,
}
Expand description
A stream
message on the iopub
channel. These are also known as “stdout” and “stderr”.
See Streams.
§Example
The UI/client sends an execute_request
message to the kernel.
use jupyter_protocol::{ExecuteRequest, JupyterMessage};
// The UI/client sends an `execute_request` message to the kernel.
let execute_request = ExecuteRequest {
code: "print('Hello, World!')".to_string(),
silent: false,
store_history: true,
user_expressions: None,
allow_stdin: false,
stop_on_error: true,
};
let incoming_message: JupyterMessage = execute_request.into();
// ...
// On the kernel side, we receive the `execute_request` message.
//
// As a side effect of execution, the kernel can send `stream` messages to the UI/client.
// These are from using `print()`, `console.log()`, or similar. Anything on STDOUT or STDERR.
use jupyter_protocol::{StreamContent, Stdio};
let message = StreamContent {
name: Stdio::Stdout,
text: "Hello, World".to_string()
// To inform the UI that the kernel is emitting this stdout in response to the execution, we
// use `as_child_of` to set the parent header.
}.as_child_of(&incoming_message);
// next, send the `message` back over the iopub connection
Fields§
§name: Stdio
§text: String
Implementations§
Source§impl StreamContent
impl StreamContent
Sourcepub fn as_child_of(&self, parent: &JupyterMessage) -> JupyterMessage
pub fn as_child_of(&self, parent: &JupyterMessage) -> JupyterMessage
Create a new JupyterMessage
, assigning the parent for a StreamContent
message.
This method creates a new JupyterMessage
with the right content, parent header, and zmq identities, making
it suitable for sending over ZeroMQ.
§Example
use jupyter_protocol::messaging::{JupyterMessage, JupyterMessageContent};
use jupyter_protocol::StreamContent;
let parent_message = JupyterMessage::new(jupyter_protocol::UnknownMessage {
msg_type: "example".to_string(),
content: serde_json::json!({ "key": "value" }),
}, None);
let child_message = StreamContent{
..Default::default()
}.as_child_of(&parent_message);
// Next you would send the `child_message` over the connection
Source§impl StreamContent
impl StreamContent
pub fn stdout(text: &str) -> StreamContent
pub fn stderr(text: &str) -> StreamContent
Trait Implementations§
Source§impl Clone for StreamContent
impl Clone for StreamContent
Source§fn clone(&self) -> StreamContent
fn clone(&self) -> StreamContent
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for StreamContent
impl Debug for StreamContent
Source§impl Default for StreamContent
impl Default for StreamContent
Source§fn default() -> StreamContent
fn default() -> StreamContent
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for StreamContent
impl<'de> Deserialize<'de> for StreamContent
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<StreamContent, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<StreamContent, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<StreamContent> for JupyterMessage
impl From<StreamContent> for JupyterMessage
Source§impl From<StreamContent> for JupyterMessageContent
impl From<StreamContent> for JupyterMessageContent
Source§fn from(content: StreamContent) -> JupyterMessageContent
fn from(content: StreamContent) -> JupyterMessageContent
Create a new JupyterMessageContent
for a StreamContent
.
Source§impl Serialize for StreamContent
impl Serialize for StreamContent
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for StreamContent
impl RefUnwindSafe for StreamContent
impl Send for StreamContent
impl Sync for StreamContent
impl Unpin for StreamContent
impl UnwindSafe for StreamContent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more