Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #176 from MindFlavor/bugfix/pr/173/pr
Browse files Browse the repository at this point in the history
migrated to std::future after PR 173
  • Loading branch information
MindFlavor authored Dec 2, 2019
2 parents 8b926c2 + 3224ac6 commit 6d22967
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 28 deletions.
2 changes: 1 addition & 1 deletion azure_sdk_storage_table/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_table"
version = "0.30.0"
version = "0.30.1"
description = "Rust wrappers around Microsoft Azure REST APIs - Table storage crate"
readme = "README.md"
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
Expand Down
14 changes: 12 additions & 2 deletions azure_sdk_storage_table/src/table/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ impl<T: Serialize> BatchItem<T> {
}
}

pub fn generate_batch_payload<T: Serialize>(uri_prefix: &str, table: &str, primary_key: &str, items: &[BatchItem<T>]) -> String {
pub fn generate_batch_payload<T: Serialize>(
uri_prefix: &str,
table: &str,
primary_key: &str,
items: &[BatchItem<T>],
) -> String {
let mut payload: String = BATCH_BEGIN.to_owned();
for item in items {
payload.push_str(CHANGESET_BEGIN);
Expand Down Expand Up @@ -107,7 +112,12 @@ If-Match: *
bupdate("Channel_17", "3", 9, "PDC 2008..."),
bdelete("3"),
];
let actual = generate_batch_payload("https://myaccount.table.core.windows.net/", "Blogs", "Channel_17", items.as_slice());
let actual = generate_batch_payload(
"https://myaccount.table.core.windows.net/",
"Blogs",
"Channel_17",
items.as_slice(),
);
assert_eq!(expected, actual);
}

Expand Down
65 changes: 40 additions & 25 deletions azure_sdk_storage_table/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,69 +339,84 @@ pub struct TableStorage {
}

impl TableStorage {
pub fn new<S:Into<String>>(service: TableService, table_name: S) -> Self {
TableStorage {
service,
table_name: table_name.into()
pub fn new<S: Into<String>>(service: TableService, table_name: S) -> Self {
TableStorage {
service,
table_name: table_name.into(),
}
}

pub fn create_table(&self) -> impl Future<Item = (), Error = AzureError> {
self.service.create_table(self.table_name.clone())
pub async fn create_table(&self) -> Result<(), AzureError> {
self.service.create_table(self.table_name.clone()).await
}

pub fn get_entity<T: DeserializeOwned>(
pub async fn get_entity<T: DeserializeOwned>(
&self,
partition_key: &str,
row_key: &str,
) -> impl Future<Item = Option<T>, Error = AzureError> {
self.service.get_entity(&self.table_name, partition_key, row_key)
) -> Result<Option<T>, AzureError> {
self.service
.get_entity(&self.table_name, partition_key, row_key)
.await
}

pub fn query_entities<T: DeserializeOwned>(
pub async fn query_entities<T: DeserializeOwned>(
&self,
query: Option<&str>,
) -> impl Future<Item = Vec<T>, Error = AzureError> {
self.service.query_entities(&self.table_name, query)
) -> Result<Vec<T>, AzureError> {
self.service.query_entities(&self.table_name, query).await
}

pub fn stream_query_entities<'a, T: DeserializeOwned + 'a>(
&'a self,
query: Option<&'a str>,
) -> impl Stream<Item = T, Error = AzureError> + 'a {
) -> impl Stream<Item = Result<Vec<T>, AzureError>> + 'a {
self.service.stream_query_entities(&self.table_name, query)
}

pub fn stream_query_entities_fullmetadata<'a, T: DeserializeOwned + 'a>(
&'a self,
query: Option<&'a str>,
) -> impl Stream<Item = T, Error = AzureError> + 'a {
self.service.stream_query_entities_fullmetadata(&self.table_name, query)
) -> impl Stream<Item = Result<Vec<T>, AzureError>> + 'a {
self.service
.stream_query_entities_fullmetadata(&self.table_name, query)
}

pub fn insert_entity<T: Serialize>(&self, entity: &T) -> impl Future<Item = (), Error = AzureError> {
self.service.insert_entity::<T>(&self.table_name, entity)
pub async fn insert_entity<T: Serialize>(&self, entity: &T) -> Result<(), AzureError> {
self.service
.insert_entity::<T>(&self.table_name, entity)
.await
}

pub fn update_entity<T: Serialize>(
pub async fn update_entity<T: Serialize>(
&self,
partition_key: &str,
row_key: &str,
entity: &T,
) -> impl Future<Item = (), Error = AzureError> {
self.service.update_entity(&self.table_name, partition_key, row_key, entity)
) -> Result<(), AzureError> {
self.service
.update_entity(&self.table_name, partition_key, row_key, entity)
.await
}

pub fn delete_entity(&self, partition_key: &str, row_key: &str) -> impl Future<Item = (), Error = AzureError> {
self.service.delete_entity(&self.table_name, partition_key, row_key)
pub async fn delete_entity(
&self,
partition_key: &str,
row_key: &str,
) -> Result<(), AzureError> {
self.service
.delete_entity(&self.table_name, partition_key, row_key)
.await
}

pub fn batch<T: Serialize>(
pub async fn batch<T: Serialize>(
&self,
partition_key: &str,
batch_items: &[BatchItem<T>],
) -> impl Future<Item = (), Error = AzureError> {
self.service.batch(&self.table_name, partition_key, batch_items)
) -> Result<(), AzureError> {
self.service
.batch(&self.table_name, partition_key, batch_items)
.await
}
}

Expand Down

0 comments on commit 6d22967

Please sign in to comment.