Skip to content

Commit

Permalink
farewell to impl types (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
analogrelay authored Oct 30, 2024
1 parent e37aea2 commit 3f86b01
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions sdk/cosmos/azure_data_cosmos/examples/cosmos/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl CreateCommand {
partition_key,
json,
} => {
let db_client = client.database_client(database);
let container_client = db_client.container_client(container);
let db_client = client.database_client(&database);
let container_client = db_client.container_client(&container);

let pk = PartitionKey::from(&partition_key);
let item: serde_json::Value = serde_json::from_str(&json)?;
Expand All @@ -85,7 +85,7 @@ impl CreateCommand {

Subcommands::Database { id } => {
let db = client
.create_database(id, None)
.create_database(&id, None)
.await?
.deserialize_body()
.await?
Expand All @@ -110,7 +110,7 @@ impl CreateCommand {
},
};
let container = client
.database_client(database)
.database_client(&database)
.create_container(properties, None)
.await?
.deserialize_body()
Expand Down
12 changes: 6 additions & 6 deletions sdk/cosmos/azure_data_cosmos/examples/cosmos/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl DeleteCommand {
item_id,
partition_key,
} => {
let db_client = client.database_client(database);
let container_client = db_client.container_client(container);
let db_client = client.database_client(&database);
let container_client = db_client.container_client(&container);

let response = container_client
.delete_item(partition_key, item_id, None)
.delete_item(partition_key, &item_id, None)
.await;
match response {
Err(e) if e.http_status() == Some(StatusCode::NotFound) => {
Expand All @@ -72,14 +72,14 @@ impl DeleteCommand {
}

Subcommands::Database { id } => {
let db_client = client.database_client(id);
let db_client = client.database_client(&id);
db_client.delete(None).await?;
Ok(())
}

Subcommands::Container { database, id } => {
let db_client = client.database_client(database);
let container_client = db_client.container_client(id);
let db_client = client.database_client(&database);
let container_client = db_client.container_client(&id);
container_client.delete(None).await?;
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions sdk/cosmos/azure_data_cosmos/examples/cosmos/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();

let args = ProgramArgs::parse();
let mut args = ProgramArgs::parse();

let Some(cmd) = args.subcommand else {
ProgramArgs::command().print_long_help()?;
return Ok(());
};

let client = create_client(&args.shared_args)?;
let client = create_client(&mut args.shared_args)?;

match cmd {
Subcommands::Create(cmd) => cmd.run(client).await,
Expand All @@ -74,11 +74,11 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
}
}

fn create_client(args: &SharedArgs) -> Result<CosmosClient, Box<dyn Error>> {
if let Some(key) = args.key.as_ref() {
fn create_client(args: &mut SharedArgs) -> Result<CosmosClient, Box<dyn Error>> {
if let Some(key) = args.key.take() {
#[cfg(feature = "key_auth")]
{
Ok(CosmosClient::with_key(&args.endpoint, key.clone(), None)?)
Ok(CosmosClient::with_key(&args.endpoint, key.into(), None)?)
}
#[cfg(not(feature = "key_auth"))]
{
Expand Down
6 changes: 3 additions & 3 deletions sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl ContainerClient {
pub async fn replace_item<T: Serialize>(
&self,
partition_key: impl Into<PartitionKey>,
item_id: impl AsRef<str>,
item_id: &str,
item: T,

#[allow(unused_variables)]
Expand Down Expand Up @@ -288,7 +288,7 @@ impl ContainerClient {
pub async fn read_item<T: DeserializeOwned>(
&self,
partition_key: impl Into<PartitionKey>,
item_id: impl AsRef<str>,
item_id: &str,

#[allow(unused_variables)]
// REASON: This is a documented public API so prefixing with '_' is undesirable.
Expand Down Expand Up @@ -323,7 +323,7 @@ impl ContainerClient {
pub async fn delete_item(
&self,
partition_key: impl Into<PartitionKey>,
item_id: impl AsRef<str>,
item_id: &str,

#[allow(unused_variables)]
// REASON: This is a documented public API so prefixing with '_' is undesirable.
Expand Down
20 changes: 10 additions & 10 deletions sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ impl CosmosClient {
/// let client = CosmosClient::new("https://myaccount.documents.azure.com/", credential, None).unwrap();
/// ```
pub fn new(
endpoint: impl AsRef<str>,
endpoint: &str,
credential: Arc<dyn TokenCredential>,
options: Option<CosmosClientOptions>,
) -> azure_core::Result<Self> {
let options = options.unwrap_or_default();
Ok(Self {
databases_link: ResourceLink::root(ResourceType::Databases),
pipeline: CosmosPipeline::new(
endpoint.as_ref().parse()?,
endpoint.parse()?,
AuthorizationPolicy::from_token_credential(credential),
options.client_options,
),
Expand All @@ -73,15 +73,15 @@ impl CosmosClient {
/// ```
#[cfg(feature = "key_auth")]
pub fn with_key(
endpoint: impl AsRef<str>,
key: impl Into<Secret>,
endpoint: &str,
key: Secret,
options: Option<CosmosClientOptions>,
) -> azure_core::Result<Self> {
let options = options.unwrap_or_default();
Ok(Self {
databases_link: ResourceLink::root(ResourceType::Databases),
pipeline: CosmosPipeline::new(
endpoint.as_ref().parse()?,
endpoint.parse()?,
AuthorizationPolicy::from_shared_key(key.into()),
options.client_options,
),
Expand All @@ -92,8 +92,8 @@ impl CosmosClient {
///
/// # Arguments
/// * `id` - The ID of the database.
pub fn database_client(&self, id: impl AsRef<str>) -> DatabaseClient {
DatabaseClient::new(self.pipeline.clone(), id.as_ref())
pub fn database_client(&self, id: &str) -> DatabaseClient {
DatabaseClient::new(self.pipeline.clone(), id)
}

/// Gets the endpoint of the database account this client is connected to.
Expand Down Expand Up @@ -148,15 +148,15 @@ impl CosmosClient {
/// * `options` - Optional parameters for the request.
pub async fn create_database(
&self,
id: String,
id: &str,

#[allow(unused_variables)]
// REASON: This is a documented public API so prefixing with '_' is undesirable.
options: Option<CreateDatabaseOptions>,
) -> azure_core::Result<Response<Item<DatabaseProperties>>> {
#[derive(Serialize)]
struct RequestBody {
id: String,
struct RequestBody<'a> {
id: &'a str,
}

let url = self.pipeline.url(&self.databases_link);
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure_data_cosmos/src/clients/database_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl DatabaseClient {
///
/// # Arguments
/// * `name` - The name of the container.
pub fn container_client(&self, name: impl AsRef<str>) -> ContainerClient {
ContainerClient::new(self.pipeline.clone(), &self.link, name.as_ref())
pub fn container_client(&self, name: &str) -> ContainerClient {
ContainerClient::new(self.pipeline.clone(), &self.link, name)
}

/// Returns the identifier of the Cosmos database.
Expand Down
4 changes: 2 additions & 2 deletions sdk/cosmos/azure_data_cosmos/src/resource_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl ResourceLink {
}
}

pub fn item(&self, item_id: impl AsRef<str>) -> Self {
let item_id = url_encode(item_id.as_ref().as_bytes());
pub fn item(&self, item_id: &str) -> Self {
let item_id = url_encode(item_id.as_bytes());
Self {
parent: self.parent.clone(),
resource_type: self.resource_type,
Expand Down

0 comments on commit 3f86b01

Please sign in to comment.