INNER CODE UNIT · Rust
client_base_url
shenmintao/marginalia · desktop/src-tauri/src/lib.rs:216
fn client_base_url(host: &str, port: u16) -> String {
let mut client_host = host.trim();
if client_host.is_empty() || client_host == "0.0.0.0" || client_host == "::" {
client_host = "127.0.0.1";
}
if client_host.contains(':') && !client_host.starts_with('[') {
format!("http://[{}]:{}", client_host, port)
} else {
format!("http://{}:{}", client_host, port)
}
}
fn local_port_from_base_url(url: &str) -> Option<u16> {
let rest = url
.strip_prefix("http://127.0.0.1:")
.or_else(|| url.strip_prefix("http://localhost:"))?;
let port = rest.split('/').next().unwrap_or(rest);
port.parse::<u16>().ok()