jupyter_protocol/
connection_info.rsuse rand::{distributions::Alphanumeric, Rng};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ConnectionInfo {
pub ip: String,
pub transport: String,
pub shell_port: u16,
pub iopub_port: u16,
pub stdin_port: u16,
pub control_port: u16,
pub hb_port: u16,
pub key: String,
pub signature_scheme: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub kernel_name: Option<String>,
}
pub fn jupyter_style_key() -> String {
let a: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(8)
.map(char::from)
.collect();
let b: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(24)
.map(char::from)
.collect();
format!("{}-{}", a, b,)
}
fn form_url(transport: &str, ip: &str, port: u16) -> String {
format!("{}://{}:{}", transport, ip, port)
}
impl ConnectionInfo {
pub fn iopub_url(&self) -> String {
form_url(&self.transport, &self.ip, self.iopub_port)
}
pub fn shell_url(&self) -> String {
form_url(&self.transport, &self.ip, self.shell_port)
}
pub fn stdin_url(&self) -> String {
form_url(&self.transport, &self.ip, self.stdin_port)
}
pub fn control_url(&self) -> String {
form_url(&self.transport, &self.ip, self.control_port)
}
pub fn hb_url(&self) -> String {
form_url(&self.transport, &self.ip, self.hb_port)
}
}