isothrum_client/client/
console.rs1use super::{ClientError, Reply, Result};
5use crate::proto::ReachedConsole;
6use crate::wire::{Reader, Writer};
7
8pub struct HeldConsole {
12 pub console: ReachedConsole,
14 pub(super) reader: Reader,
15 pub(super) _writer: Writer,
16}
17
18impl HeldConsole {
19 pub async fn closed(&mut self) -> String {
23 loop {
24 match self.reader.next::<Reply>().await {
25 Ok(Some(Reply::ConsoleClosed { reason, .. })) => return reason,
26 Ok(Some(_)) => {}
27 Ok(None) => return "the runner service closed the connection".to_owned(),
28 Err(e) => return format!("the runner service's connection broke: {e}"),
29 }
30 }
31 }
32}
33
34impl std::fmt::Debug for HeldConsole {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 f.debug_struct("HeldConsole").field("console", &self.console).finish_non_exhaustive()
37 }
38}
39
40pub(super) fn of_reply(reply: Option<Reply>) -> Result<ReachedConsole> {
42 match reply {
43 Some(Reply::Console { console, .. }) => Ok(*console),
44 Some(Reply::Error { report, .. }) => Err(ClientError::Refused(Box::new(report))),
45 Some(other) => Err(super::unexpected(&other)),
46 None => Err(ClientError::closed()),
47 }
48}