Initial commit (history reset)

This commit is contained in:
2025-07-09 07:18:46 -05:00
commit da8a4ce5a5
8 changed files with 366 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
use std::{
io::{self, Write},
os::unix::net::UnixStream,
path::Path,
process::Command,
};
use crate::read_line;
pub trait BinderArg {
fn from_u8_bind(b: u8) -> Self;
}
pub struct DynLib {
stream: UnixStream,
}
impl DynLib {
pub fn load(dyn_lib: &str) -> io::Result<Self> {
if !Path::new(&format!("/tmp/{dyn_lib}")).exists() {
let path = format!("./{dyn_lib}.dyn");
Command::new(path).spawn().unwrap();
std::thread::sleep(std::time::Duration::from_millis(100));
}
Ok(Self {
stream: UnixStream::connect(format!("/tmp/{dyn_lib}"))?,
})
}
pub fn call<T: BinderArg>(&mut self, fn_id: u8) -> Option<T> {
self.stream.write_all(&[fn_id, 255]).ok()?;
self.stream.flush().ok()?;
let msg = read_line(&mut self.stream)?;
Some(T::from_u8_bind(msg[0]))
}
}
impl BinderArg for () {
fn from_u8_bind(_: u8) -> Self {}
}