From 85c4bda731e445ce870388ea713ebc2d37d3931d Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Wed, 8 Jun 2022 17:45:45 +0200 Subject: [PATCH 1/4] Change DIDUrl::join to borrow self --- bindings/wasm/src/did/wasm_did_url.rs | 2 +- identity-did/src/did/did_url.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bindings/wasm/src/did/wasm_did_url.rs b/bindings/wasm/src/did/wasm_did_url.rs index a1f591c6f2..7ef71bc8e2 100644 --- a/bindings/wasm/src/did/wasm_did_url.rs +++ b/bindings/wasm/src/did/wasm_did_url.rs @@ -79,7 +79,7 @@ impl WasmDIDUrl { /// - joining a query will clear the fragment. /// - joining a fragment will only overwrite the fragment. #[wasm_bindgen] - pub fn join(self, segment: &str) -> Result { + pub fn join(&self, segment: &str) -> Result { self.0.join(segment).map(WasmDIDUrl::from).wasm_result() } diff --git a/identity-did/src/did/did_url.rs b/identity-did/src/did/did_url.rs index 399a5c9a75..3890986710 100644 --- a/identity-did/src/did/did_url.rs +++ b/identity-did/src/did/did_url.rs @@ -393,7 +393,7 @@ where /// - joining a path will overwrite the path and clear the query and fragment. /// - joining a query will overwrite the query and clear the fragment. /// - joining a fragment will only overwrite the fragment. - pub fn join(self, segment: impl AsRef) -> Result { + pub fn join(&self, segment: impl AsRef) -> Result { let segment: &str = segment.as_ref(); // Accept only a relative path, query, or fragment to reject altering the method id segment. @@ -662,13 +662,13 @@ mod tests { #[test] fn test_join_valid() { let did_url = CoreDIDUrl::parse("did:example:1234567890").unwrap(); - assert_eq!(did_url.clone().join("/path").unwrap().to_string(), "did:example:1234567890/path"); - assert_eq!(did_url.clone().join("?query").unwrap().to_string(), "did:example:1234567890?query"); - assert_eq!(did_url.clone().join("#fragment").unwrap().to_string(), "did:example:1234567890#fragment"); + assert_eq!(did_url.join("/path").unwrap().to_string(), "did:example:1234567890/path"); + assert_eq!(did_url.join("?query").unwrap().to_string(), "did:example:1234567890?query"); + assert_eq!(did_url.join("#fragment").unwrap().to_string(), "did:example:1234567890#fragment"); - assert_eq!(did_url.clone().join("/path?query").unwrap().to_string(), "did:example:1234567890/path?query"); - assert_eq!(did_url.clone().join("/path#fragment").unwrap().to_string(), "did:example:1234567890/path#fragment"); - assert_eq!(did_url.clone().join("?query#fragment").unwrap().to_string(), "did:example:1234567890?query#fragment"); + assert_eq!(did_url.join("/path?query").unwrap().to_string(), "did:example:1234567890/path?query"); + assert_eq!(did_url.join("/path#fragment").unwrap().to_string(), "did:example:1234567890/path#fragment"); + assert_eq!(did_url.join("?query#fragment").unwrap().to_string(), "did:example:1234567890?query#fragment"); let did_url = did_url.join("/path?query#fragment").unwrap(); assert_eq!(did_url.to_string(), "did:example:1234567890/path?query#fragment"); @@ -684,9 +684,9 @@ mod tests { assert!(CoreDIDUrl::parse("did:example:1234567890#invalid{fragment}").is_err()); let did_url = CoreDIDUrl::parse("did:example:1234567890").unwrap(); - assert!(did_url.clone().join("noleadingdelimiter").is_err()); - assert!(did_url.clone().join("/invalid{path}").is_err()); - assert!(did_url.clone().join("?invalid{query}").is_err()); + assert!(did_url.join("noleadingdelimiter").is_err()); + assert!(did_url.join("/invalid{path}").is_err()); + assert!(did_url.join("?invalid{query}").is_err()); assert!(did_url.join("#invalid{fragment}").is_err()); } From 4905d48e0f88243a358d441d9fa188568f31366c Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Wed, 8 Jun 2022 17:53:36 +0200 Subject: [PATCH 2/4] Update doc-comments --- bindings/wasm/docs/api-reference.md | 2 +- bindings/wasm/src/did/wasm_did_url.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bindings/wasm/docs/api-reference.md b/bindings/wasm/docs/api-reference.md index aa6d413d85..14baa5b0da 100644 --- a/bindings/wasm/docs/api-reference.md +++ b/bindings/wasm/docs/api-reference.md @@ -1426,7 +1426,7 @@ Sets the `query` component of the `DIDUrl`. ### didUrl.join(segment) ⇒ [DIDUrl](#DIDUrl) -Append a string representing a path, query, and/or fragment to this `DIDUrl`. +Append a string representing a path, query, and/or fragment, returning a new `DIDUrl`. Must begin with a valid delimiter character: '/', '?', '#'. Overwrites the existing URL segment and any following segments in order of path, query, then fragment. diff --git a/bindings/wasm/src/did/wasm_did_url.rs b/bindings/wasm/src/did/wasm_did_url.rs index 7ef71bc8e2..45837a2dd4 100644 --- a/bindings/wasm/src/did/wasm_did_url.rs +++ b/bindings/wasm/src/did/wasm_did_url.rs @@ -69,7 +69,7 @@ impl WasmDIDUrl { self.0.set_query(value.as_deref()).wasm_result() } - /// Append a string representing a path, query, and/or fragment to this `DIDUrl`. + /// Append a string representing a path, query, and/or fragment, returning a new `DIDUrl`. /// /// Must begin with a valid delimiter character: '/', '?', '#'. Overwrites the existing URL /// segment and any following segments in order of path, query, then fragment. From 5613758de0a0e79e9a8960acd784394caa9bdb56 Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Wed, 8 Jun 2022 17:54:20 +0200 Subject: [PATCH 3/4] Update doc-comments --- identity-did/src/did/did_url.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/identity-did/src/did/did_url.rs b/identity-did/src/did/did_url.rs index 3890986710..4ea414a5dc 100644 --- a/identity-did/src/did/did_url.rs +++ b/identity-did/src/did/did_url.rs @@ -384,7 +384,7 @@ where self.url.query_pairs() } - /// Append a string representing a `path`, `query`, and/or `fragment` to this [`DIDUrl`]. + /// Append a string representing a `path`, `query`, and/or `fragment`, returning a new [`DIDUrl`]. /// /// Must begin with a valid delimiter character: '/', '?', '#'. Overwrites the existing URL /// segment and any following segments in order of path, query, then fragment. From 17979763cc76e94d4c91e2ad06303e21b1ec13b5 Mon Sep 17 00:00:00 2001 From: Craig Bester Date: Wed, 8 Jun 2022 18:05:57 +0200 Subject: [PATCH 4/4] Remove unused dependency --- identity-did/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/identity-did/Cargo.toml b/identity-did/Cargo.toml index 21472ce5df..22f733a0bf 100644 --- a/identity-did/Cargo.toml +++ b/identity-did/Cargo.toml @@ -11,7 +11,6 @@ repository = "https://github.com/iotaledger/identity.rs" description = "An implementation of the Decentralized Identifiers standard." [dependencies] -async-trait = { version = "0.1", default-features = false } did_url = { version = "0.1", default-features = false, features = ["std", "serde"] } form_urlencoded = { version = "1.0.1", default-features = false } identity-core = { version = "=0.5.0", path = "../identity-core" }