Skip to content

Commit

Permalink
remove clone bounds from cosmos client creation
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshuawuyts committed Jul 1, 2022
1 parent b68af10 commit 6702759
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> azure_core::Result<()> {
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

// Create a new Cosmos client.
let client = CosmosClient::new(args.account.clone(), authorization_token.clone());
let client = CosmosClient::new(args.account, authorization_token);

// Create a new database, and time out if it takes more than 1 second.
let future = client.create_database("my_database").into_future();
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn main() -> azure_core::Result<()> {
// authorization token at later time if you need, for example, to escalate the privileges for a
// single operation.
// Here we are using reqwest but other clients are supported (check the documentation).
let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(&args.account, authorization_token);

// The Cosmos' client exposes a lot of methods. This one lists the databases in the specified account.
let databases = client
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/document_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> azure_core::Result<()> {

// Next we will create a Cosmos client. You need an authorization_token but you can later
// change it if needed.
let client = CosmosClient::new(args.account.clone(), authorization_token.clone());
let client = CosmosClient::new(args.account, authorization_token);

// list_databases will give us the databases available in our account. If there is
// an error (for example, the given key is not valid) you will receive a
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/get_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let database = client.database_client(args.database_name.clone());

let mut context = Context::new();
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/key_ranges_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token)
let client = CosmosClient::new(args.account, authorization_token)
.database_client(args.database_name)
.collection_client(args.collection_name);

Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/permission_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);

let database = client.database_client(args.database_name);
let collection = database.collection_client(args.collection_name);
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/query_document_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token)
let client = CosmosClient::new(args.account, authorization_token)
.database_client(args.database_name)
.collection_client(args.collection_name);

Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() -> azure_core::Result<()> {
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

// Next we will create a Cosmos client.
let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);

// We know the database so we can obtain a database client.
let database = client.database_client(args.database_name);
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/remove_all_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> azure_core::Result<()> {
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

// Next we will create a Cosmos client.
let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let collection = client
.database_client(args.database_name)
.collection_client(args.collection_name);
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/stored_proc_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);

let ret = client
.database_client(args.database_name)
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/stored_proc_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let collection = CosmosClient::new(args.account.clone(), authorization_token)
let collection = CosmosClient::new(args.account, authorization_token)
.database_client(args.database_name)
.collection_client(args.collection_name);
let stored_procedure = collection.stored_procedure_client(args.stored_procedure_name);
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/trigger_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let database = client.database_client(args.database_name);
let collection = database.collection_client(args.collection_name);
let trigger = collection.clone().trigger_client(args.trigger_name);
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/user_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let database = client.database_client(args.database_name);
let user = database.user_client(args.user_name.clone());

Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/user_defined_function_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn main() -> azure_core::Result<()> {
let args = Args::parse();
let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let database = client.database_client(args.database_name);
let collection = database.collection_client(args.collection_name);
let user_defined_function = collection.user_defined_function_client("test15");
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/examples/user_permission_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn main() -> azure_core::Result<()> {

let authorization_token = AuthorizationToken::primary_from_base64(&args.primary_key)?;

let client = CosmosClient::new(args.account.clone(), authorization_token);
let client = CosmosClient::new(args.account, authorization_token);
let database = client.database_client(args.database_name.clone());
let collection = database.collection_client(args.collection_name.clone());
let user = database.user_client(args.user_name);
Expand Down
19 changes: 12 additions & 7 deletions sdk/data_cosmos/src/clients/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub struct CosmosClient {

impl CosmosClient {
/// Create a new `CosmosClient` which connects to the account's instance in the public Azure cloud.
pub fn new(account: String, auth_token: AuthorizationToken) -> Self {
pub fn new(account: impl Into<String>, auth_token: AuthorizationToken) -> Self {
Self {
pipeline: new_pipeline_from_options(ClientOptions::default(), auth_token),
cloud_location: CloudLocation::Public(account),
cloud_location: CloudLocation::Public(account.into()),
}
}

Expand All @@ -45,29 +45,34 @@ impl CosmosClient {
}

/// Create a new `CosmosClient` which connects to the account's instance in the Chinese Azure cloud.
pub fn new_china(account: String, auth_token: AuthorizationToken) -> Self {
pub fn new_china(account: impl Into<String>, auth_token: AuthorizationToken) -> Self {
Self {
pipeline: new_pipeline_from_options(ClientOptions::default(), auth_token),
cloud_location: CloudLocation::China(account),
cloud_location: CloudLocation::China(account.into()),
}
}

/// Create a new `CosmosClient` which connects to the account's instance in custom Azure cloud.
pub fn new_custom(account: String, auth_token: AuthorizationToken, uri: String) -> Self {
pub fn new_custom(
account: impl Into<String>,
auth_token: AuthorizationToken,
uri: String,
) -> Self {
let account = account.into();
Self {
pipeline: new_pipeline_from_options(ClientOptions::default(), auth_token),
cloud_location: CloudLocation::Custom { account, uri },
}
}

/// Create a new `CosmosClient` which connects to the account's instance in Azure emulator
pub fn new_emulator(address: &str, port: u16) -> Self {
pub fn new_emulator(address: impl AsRef<str>, port: u16) -> Self {
let auth_token = AuthorizationToken::primary_from_base64(EMULATOR_ACCOUNT_KEY).unwrap();
Self {
pipeline: new_pipeline_from_options(ClientOptions::default(), auth_token),
cloud_location: CloudLocation::Custom {
account: String::from("Custom"),
uri: format!("https://{}:{}", address, port),
uri: format!("https://{}:{}", address.as_ref(), port),
},
}
}
Expand Down

0 comments on commit 6702759

Please sign in to comment.