This commit is contained in:
John Smith
2021-11-27 12:44:21 -05:00
parent d1f728954c
commit 028e02f942
31 changed files with 190 additions and 207 deletions
+7 -5
View File
@@ -1,20 +1,22 @@
use crate::xx::*;
use alloc::string::ToString;
pub fn split_port(name: &str) -> Result<(String, u16), ()> {
pub fn split_port(name: &str) -> Result<(String, Option<u16>), String> {
if let Some(split) = name.rfind(':') {
let hoststr = &name[0..split];
let portstr = &name[split + 1..];
let port: u16 = portstr.parse::<u16>().map_err(drop)?;
let port: u16 = portstr
.parse::<u16>()
.map_err(|e| format!("Invalid port: {}", e))?;
Ok((hoststr.to_string(), port))
Ok((hoststr.to_string(), Some(port)))
} else {
Err(())
Ok((name.to_string(), None))
}
}
pub fn prepend_slash(s: String) -> String {
if s.starts_with("/") {
if s.starts_with('/') {
return s;
}
let mut out = "/".to_owned();