|
1 | 1 | use super::{ |
2 | 2 | AttributesIntoIteratorV03, AttributesIntoIteratorV10, AttributesV03, AttributesV10, |
3 | | - ExtensionValue, SpecVersion, UriReference, |
| 3 | + ExtensionValue, SpecVersion, |
| 4 | + types::* |
4 | 5 | }; |
5 | 6 | use chrono::{DateTime, Utc}; |
6 | 7 | use serde::Serializer; |
7 | 8 | use std::fmt; |
8 | | -use url::Url; |
9 | 9 |
|
10 | 10 | /// Enum representing a borrowed value of a CloudEvent attribute. |
11 | 11 | /// This represents the types defined in the [CloudEvent spec type system](https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system) |
12 | 12 | #[derive(Debug, PartialEq, Eq)] |
13 | 13 | pub enum AttributeValue<'a> { |
14 | 14 | SpecVersion(SpecVersion), |
15 | 15 | String(&'a str), |
16 | | - URI(&'a Url), |
| 16 | + URI(&'a Uri), |
17 | 17 | URIRef(&'a UriReference), |
18 | 18 | Boolean(&'a bool), |
19 | 19 | Integer(&'a i64), |
@@ -57,7 +57,7 @@ pub trait AttributesReader { |
57 | 57 | /// Get the [datacontenttype](https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype). |
58 | 58 | fn datacontenttype(&self) -> Option<&str>; |
59 | 59 | /// Get the [dataschema](https://github.com/cloudevents/spec/blob/master/spec.md#dataschema). |
60 | | - fn dataschema(&self) -> Option<&Url>; |
| 60 | + fn dataschema(&self) -> Option<&Uri>; |
61 | 61 | /// Get the [subject](https://github.com/cloudevents/spec/blob/master/spec.md#subject). |
62 | 62 | fn subject(&self) -> Option<&str>; |
63 | 63 | /// Get the [time](https://github.com/cloudevents/spec/blob/master/spec.md#time). |
@@ -87,7 +87,7 @@ pub trait AttributesWriter { |
87 | 87 | -> Option<String>; |
88 | 88 | /// Set the [dataschema](https://github.com/cloudevents/spec/blob/master/spec.md#dataschema). |
89 | 89 | /// Returns the previous value. |
90 | | - fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>) -> Option<Url>; |
| 90 | + fn set_dataschema(&mut self, dataschema: Option<impl Into<Uri>>) -> Option<Uri>; |
91 | 91 | } |
92 | 92 |
|
93 | 93 | pub(crate) trait AttributesConverter { |
@@ -154,7 +154,7 @@ impl AttributesReader for Attributes { |
154 | 154 | } |
155 | 155 | } |
156 | 156 |
|
157 | | - fn dataschema(&self) -> Option<&Url> { |
| 157 | + fn dataschema(&self) -> Option<&Uri> { |
158 | 158 | match self { |
159 | 159 | Attributes::V03(a) => a.dataschema(), |
160 | 160 | Attributes::V10(a) => a.dataschema(), |
@@ -222,7 +222,7 @@ impl AttributesWriter for Attributes { |
222 | 222 | } |
223 | 223 | } |
224 | 224 |
|
225 | | - fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>) -> Option<Url> { |
| 225 | + fn set_dataschema(&mut self, dataschema: Option<impl Into<Uri>>) -> Option<Uri> { |
226 | 226 | match self { |
227 | 227 | Attributes::V03(a) => a.set_dataschema(dataschema), |
228 | 228 | Attributes::V10(a) => a.set_dataschema(dataschema), |
@@ -253,31 +253,27 @@ impl Attributes { |
253 | 253 | } |
254 | 254 |
|
255 | 255 | #[cfg(not(target_arch = "wasm32"))] |
256 | | -pub(crate) fn default_hostname() -> Url { |
257 | | - Url::parse( |
258 | | - format!( |
259 | | - "http://{}", |
260 | | - hostname::get() |
261 | | - .ok() |
262 | | - .map(|s| s.into_string().ok()) |
263 | | - .flatten() |
264 | | - .unwrap_or_else(|| "localhost".to_string()) |
265 | | - ) |
266 | | - .as_ref(), |
| 256 | +pub(crate) fn default_hostname() -> Uri { |
| 257 | + format!( |
| 258 | + "http://{}", |
| 259 | + hostname::get() |
| 260 | + .ok() |
| 261 | + .map(|s| s.into_string().ok()) |
| 262 | + .flatten() |
| 263 | + .unwrap_or_else(|| "localhost".to_string()) |
267 | 264 | ) |
| 265 | + .into_uri() |
268 | 266 | .unwrap() |
269 | 267 | } |
270 | 268 |
|
271 | 269 | #[cfg(target_arch = "wasm32")] |
272 | | -pub(crate) fn default_hostname() -> Url { |
| 270 | +pub(crate) fn default_hostname() -> Uri { |
273 | 271 | use std::str::FromStr; |
274 | 272 |
|
275 | | - Url::from_str( |
276 | | - web_sys::window() |
277 | | - .map(|w| w.location().host().ok()) |
278 | | - .flatten() |
279 | | - .unwrap_or(String::from("http://localhost")) |
280 | | - .as_str(), |
281 | | - ) |
282 | | - .unwrap() |
| 273 | + web_sys::window() |
| 274 | + .map(|w| w.location().host().ok()) |
| 275 | + .flatten() |
| 276 | + .unwrap_or(String::from("http://localhost")) |
| 277 | + .into_uri() |
| 278 | + .unwrap() |
283 | 279 | } |
0 commit comments