Skip to content

Commit

Permalink
Merge pull request #203 from Feelemoon/feature-async-client-get-serve…
Browse files Browse the repository at this point in the history
…r-uri

Expose server_uri with AsyncClient
  • Loading branch information
fpagliughi authored Oct 25, 2023
2 parents 15e33a6 + 6ce48e7 commit 1206f20
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/async_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,14 @@ impl AsyncClient {
pub fn client_id(&self) -> String {
self.inner.client_id.clone().into_string().unwrap()
}

/// Returns server URI used for connection
///
/// Server URI is returned as a rust String as set in a
/// CreateOptionsBuilder for symmetry
pub fn server_uri(&self) -> String {
self.inner.server_uri.clone().into_string().unwrap()
}
}

// The client is safe to send or share between threads.
Expand Down Expand Up @@ -1385,4 +1393,18 @@ mod tests {
let retrieved = client.unwrap().client_id();
assert_eq!(retrieved, c_id.to_string());
}

#[test]
fn test_get_server_uri() {
let server_uri = "tcp://localhost:1883";
let client = CreateOptionsBuilder::new()
.server_uri(server_uri)
.create_client();
assert!(
client.is_ok(),
"Error in creating async client with server_uri"
);
let retrieved = client.unwrap().server_uri();
assert_eq!(retrieved, server_uri.to_string());
}
}

0 comments on commit 1206f20

Please sign in to comment.