gear_node_wrapper/
instance.rs1use crate::Log;
5use anyhow::{Result, anyhow};
6use std::{net::SocketAddrV4, process::Child};
7
8pub struct NodeInstance {
12 pub address: SocketAddrV4,
14 pub(crate) log: Log,
16 pub(crate) process: Child,
18}
19
20impl NodeInstance {
21 pub fn ws(&self) -> String {
25 format!("ws://{}", self.address)
26 }
27
28 pub fn logs(&self) -> Result<Vec<String>> {
30 let Ok(logs) = self.log.logs.read() else {
31 return Err(anyhow!("Failed to read logs from the node process."));
32 };
33
34 Ok(logs.clone().into_vec())
35 }
36}
37
38impl Drop for NodeInstance {
39 fn drop(&mut self) {
40 self.process.kill().expect("Unable to kill node process.")
41 }
42}