pub fn run_server(
tool: ToolFn,
index_html: Option<&'static str>,
) -> Result<(), Error>Expand description
Starts a server, running tool in parallel for every requesting client.
Routes:
/(GET): Returns an optional static web page (index_html) or 404/tool(WebSocket): Runs the tool, pass this url tocall
tool is a blocking function that implements the actual business logic of
this server. It runs on a separate thread and will not block the server from
hanlding more requests in parallel. See ToolFn for more details.
ยงExamples
fn main() -> Result<(), std::io::Error> {
run_server(tool, Some(INDEX_HTML))
}
fn tool(input: Value, send_msg: &mut MessageFn) -> Result<Value, ToolError> {
send_msg(format!("Args: {input:?}")).map_err(|_| ToolError::Abort)?;
Ok(input)
}
const INDEX_HTML: &'static str = "
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>My fancy tool</title>
</head>
<body>
<p>This tool debug prints all passed values and returns them to sender</p>
</body>
</html>
";