[dependencies] clap = { version = "4", features = ["derive"] } # Below is for the serve cmd hyper = { version = "0.14.1", default-features = false, features = ["runtime", "server", "http2", "http1"] } tokio = { version = "1.0.1", default-features = false, features = ["rt", "fs", "time"] } ctrlc = "3" open = "5" # For mimetype detection in serve mode mime_guess = "2.0" # For essence_str() function, see https://github.com/getzola/zola/issues/1845 mime = "0.3.16"
// 检查端口是否可用 letmut port = cli.port; if port != 1111 && !port_is_available(port) { println!("Error: {}", "The requested port is not available"); std::process::exit(1); }
if !port_is_available(port) { port = get_available_port(1111).unwrap_or_else(|| { println!("Error: {}", "No port available"); std::process::exit(1); }); }
fnserve(root_dir: &Path, interface: &str, interface_port: u16, open: bool ) ->Result<()> { letaddress = format!("{}:{}", interface, interface_port); // Stop right there if we can't bind to the address letbind_address: SocketAddrV4 = match address.parse() { Ok(a) => a, Err(_) => returnErr(anyhow!("Invalid address: {}.", address)), }; //检查端口是否可用 if (TcpListener::bind(bind_address)).is_err() { returnErr(anyhow!("Cannot start server on address {}.", address)); }