web_url/parse/
from_str.rs1use std::str::FromStr;
2
3use crate::parse::finalize::finalize_web_url;
4use crate::parse::path_plus::{parse_path_plus, PathPlus};
5use crate::parse::pre_path::{parse_pre_path, PrePath};
6use crate::parse::Error;
7use crate::WebUrl;
8
9impl FromStr for WebUrl {
10 type Err = Error;
11
12 fn from_str(s: &str) -> Result<Self, Self::Err> {
13 let pre_path: PrePath = parse_pre_path(s)?;
14 let path_plus: &str = &s[pre_path.len()..];
15
16 if path_plus.is_empty() {
17 let mut url: String = String::with_capacity(pre_path.len() + 1);
18 url.push_str(s);
19 url.push('/');
20
21 let path_plus: PathPlus = parse_path_plus("/")?;
22 unsafe { finalize_web_url(url, pre_path, path_plus).map_err(|(e, _)| e) }
23 } else {
24 let url: String = s.to_string();
25 let path_plus: PathPlus = parse_path_plus(path_plus)?;
26 unsafe { finalize_web_url(url, pre_path, path_plus).map_err(|(e, _)| e) }
27 }
28 }
29}