Skip to content

Commit

Permalink
Pretty Print Rust object when called from Python print
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed May 20, 2024
1 parent bdecc71 commit b5de93e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apis/python/operator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pyo3::{exceptions::PyLookupError, prelude::*, types::PyDict};

/// Dora Event
#[pyclass]
#[derive(Debug)]
pub struct PyEvent {
event: MergedEvent<PyObject>,
data: Option<ArrayRef>,
Expand Down Expand Up @@ -56,6 +57,10 @@ impl PyEvent {
MergedEvent::External(event) => Some(event),
}
}

fn __str__(&self) -> PyResult<String> {
Ok(format!("{:#?}", &self.event))
}
}

impl PyEvent {
Expand Down
1 change: 1 addition & 0 deletions apis/rust/node/src/event_stream/merged.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use futures::{Stream, StreamExt};
use futures_concurrency::stream::Merge;

#[derive(Debug)]
pub enum MergedEvent<E> {
Dora(super::Event),
External(E),
Expand Down

0 comments on commit b5de93e

Please sign in to comment.