1use core::str::FromStr;
2use core::fmt::Display;
3use num::Float;
4use crate::{HType, HVal, NumTrait};
5use std::fmt::{self,Write};
6
7use url::{Url,ParseError as UrlParseError};
8
9#[derive(Debug,PartialEq)]
10pub struct HUri(Url);
11
12pub type Uri = HUri;
13
14const THIS_TYPE: HType = HType::Uri;
15
16impl HUri {
17 pub fn new(input: &str) -> Result<HUri, UrlParseError> {
18 let url = Url::parse(input)?;
19 Ok(HUri(url))
20 }
21}
22
23impl <'a,T: NumTrait + 'a>HVal<'a,T> for HUri {
24 fn to_zinc(&self, buf: &mut String) -> fmt::Result {
25 buf.push('`');
26 buf.push_str(self.0.as_str());
27 buf.push('`');
28 Ok(())
29 }
30 fn to_json(&self, buf: &mut String) -> fmt::Result {
31 write!(buf,"u:{}",self.0)?;
32 Ok(())
33 }
34 fn haystack_type(&self) -> HType { THIS_TYPE }
35
36 set_trait_eq_method!(get_uri_val,'a,T);
37 set_get_method!(get_uri_val, HUri);
38}