Skip to content

Commit

Permalink
Using opaque identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
KiChjang committed May 23, 2015
1 parent aec7d49 commit 08ea09c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ pub struct Url {
pub fragment: Option<String>,
}

/// Opaque identifier for URLs that have file or other schemes
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct OpaqueOrigin(Uuid);

/// The origin of the URL
#[derive(PartialEq, Eq, Clone, Debug)]
pub enum Origin {
/// A globally unique identifier
UID(String),
UID(OpaqueOrigin),

/// Consists of the URL's scheme, host and port
Tuple(String, Host, u16)
Expand Down Expand Up @@ -577,16 +581,16 @@ impl Url {
let result = Url::parse(self.non_relative_scheme_data().unwrap());
match result {
Ok(ref url) => url.origin(),
Err(_) => Origin::UID(Uuid::new_v4().to_string())
Err(_) => Origin::UID(OpaqueOrigin(Uuid::new_v4()))
}
},
"ftp" | "gopher" | "http" | "https" | "ws" | "wss" => {
Origin::Tuple(self.scheme.clone(), self.host().unwrap().clone(),
self.port_or_default().unwrap())
},
// TODO: Figure out what to do if the scheme is a file
"file" => Origin::UID(Uuid::new_v4().to_string()),
_ => Origin::UID(Uuid::new_v4().to_string())
"file" => Origin::UID(OpaqueOrigin(Uuid::new_v4())),
_ => Origin::UID(OpaqueOrigin(Uuid::new_v4()))
}
}

Expand Down

0 comments on commit 08ea09c

Please sign in to comment.