pub struct RemoteServer {
pub base_url: String,
pub token: String,
}
Fields§
§base_url: String
§token: String
Implementations§
Source§impl RemoteServer
impl RemoteServer
pub fn from_url(url: &str) -> Result<Self>
pub fn api_url(&self, path: &str) -> String
Sourcepub async fn connect_to_kernel(
&self,
kernel_id: &str,
) -> Result<(JupyterWebSocket, Response<Option<Vec<u8>>>)>
pub async fn connect_to_kernel( &self, kernel_id: &str, ) -> Result<(JupyterWebSocket, Response<Option<Vec<u8>>>)>
Connect to a kernel by ID
use jupyter_websocket_client::RemoteServer;
use jupyter_protocol::{KernelInfoRequest, JupyterMessageContent};
// Import the sink and stream extensions to allow splitting the socket into a writer and reader pair
use futures::{SinkExt as _, StreamExt as _};
pub async fn connect_kernel() -> anyhow::Result<()> {
let server = RemoteServer::from_url(
"http://127.0.0.1:8888/lab?token=f487535a46268da4a0752c0e162c873b721e33a9e6ec8390"
)?;
// You'll need to launch a kernel and get a kernel ID using your own HTTP
// request library
let kernel_id = "1057-1057-1057-1057";
let (kernel_socket, response) = server.connect_to_kernel(kernel_id).await?;
let (mut w, mut r) = kernel_socket.split();
w.send(KernelInfoRequest {}.into()).await?;
while let Some(response) = r.next().await.transpose()? {
match response.content {
JupyterMessageContent::KernelInfoReply(kernel_info_reply) => {
println!("Received kernel_info_reply");
println!("{:?}", kernel_info_reply);
break;
}
other => {
println!("Received");
println!("{:?}", other);
}
}
}
Ok(())
}
Auto Trait Implementations§
impl Freeze for RemoteServer
impl RefUnwindSafe for RemoteServer
impl Send for RemoteServer
impl Sync for RemoteServer
impl Unpin for RemoteServer
impl UnwindSafe for RemoteServer
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