Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage crate reorg and cleanup #194

Merged
merged 4 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ macro_rules! create_enum {
)*
}

impl ::std::convert::Into<&'static str> for $name {
fn into(self) -> &'static str {
match self {
impl ::std::convert::From<$name> for &'static str {
fn from(e: $name) -> Self {
match e {
$(
$name::$variant => $value,
)*
Expand Down
11 changes: 4 additions & 7 deletions sdk/core/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl FromStringOptional<bool> for bool {

impl FromStringOptional<chrono::DateTime<chrono::Utc>> for chrono::DateTime<chrono::Utc> {
fn from_str_optional(s: &str) -> Result<chrono::DateTime<chrono::Utc>, TraversingError> {
from_azure_time(s).map_err(|e| TraversingError::DateTimeParseError(e))
from_azure_time(s).map_err(TraversingError::DateTimeParseError)
}
}

Expand Down Expand Up @@ -82,8 +82,7 @@ pub mod rfc2822_time_format_optional {
S: Serializer,
{
if let Some(date) = date {
let s = format!("{}", date.to_rfc2822());
serializer.serialize_str(&s)
serializer.serialize_str(&date.to_rfc2822())
} else {
serializer.serialize_none()
}
Expand Down Expand Up @@ -150,9 +149,7 @@ pub fn traverse<'a>(
// debug!("path.len() == {:?}", path.len());

if path.is_empty() {
let mut vec = Vec::new();
vec.push(node);
return Ok(vec);
return Ok(vec![node]);
}

let mut curnode = node;
Expand Down Expand Up @@ -234,7 +231,7 @@ where
{
let node = traverse_single_must(node, path)?;
let itxt = inner_text(node)?;
Ok(T::from_str_optional(itxt)?)
T::from_str_optional(itxt)
}

#[cfg(test)]
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/src/request_options/ba512_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ impl BA512Range {
}
}

impl Into<Range> for BA512Range {
fn into(self) -> Range {
Range {
start: self.start(),
end: self.end(),
impl From<BA512Range> for Range {
fn from(range: BA512Range) -> Self {
Self {
start: range.start(),
end: range.end(),
}
}
}
Expand Down
22 changes: 17 additions & 5 deletions sdk/core/src/request_options/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct Metadata(HashMap<String, Bytes>);

impl Metadata {
pub fn new() -> Self {
Self(HashMap::new())
impl Default for Metadata {
fn default() -> Self {
Self::new()
}
}

pub fn as_mut(&mut self) -> &mut HashMap<String, Bytes> {
impl AsMut<HashMap<String, Bytes>> for Metadata {
fn as_mut(&mut self) -> &mut HashMap<String, Bytes> {
&mut self.0
}
}

impl Metadata {
pub fn new() -> Self {
Self(HashMap::new())
}

pub fn insert<K, V>(&mut self, k: K, v: V) -> Option<Bytes>
where
Expand All @@ -28,8 +36,12 @@ impl Metadata {
self.0.len()
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}

pub fn get(&self, k: &str) -> Option<Bytes> {
self.0.get(k).map(|b| b.clone())
self.0.get(k).cloned()
}
}

Expand Down
4 changes: 2 additions & 2 deletions sdk/core/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ fn format<D: Display>(value: D) -> String {
pub fn to_str_without_bom(bytes: &bytes::Bytes) -> Result<&str, std::str::Utf8Error> {
let s = from_utf8(bytes)?;

Ok(if s.starts_with('\u{FEFF}') {
&s[3..]
Ok(if let Some(stripped) = s.strip_prefix('\u{FEFF}') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think the following is clearer:

s.strip_prefix('...').unwrap_or(s)

stripped
} else {
s
})
Expand Down
174 changes: 159 additions & 15 deletions sdk/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,184 @@ base64 = "0.13"
chrono = "0.4"
http = "0.2"
futures = "0.3"
hyper = "0.14"
log = "0.4"
mime = "0.3"
quick-error = "1.2"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
serde-xml-rs = "0.4"
time = "0.2"
url = "2.2"
uuid = { version = "0.8", features = ["v4"] }
smallvec = { version = "1.6", features = ["serde"] }
bytes = "1.0"
hyper-rustls = "0.22"
md5 = "0.7"
RustyXML = "0.3"
percent-encoding = "2.1"
failure = "0.1"
thiserror = "1.0"
once_cell = "1.7"

[dev-dependencies]
tokio = { version = "1.0", features = ["macros"] }
env_logger = "0.8"
azure_identity = { path = "../identity" }
url = "2.2"
reqwest = "0.11"

[features]
default = ["account", "blob", "queue", "table", "data_lake"]
test_e2e = ["account", "blob", "queue", "table", "data_lake"]
account = []
default = ["storage_account", "blob_storage", "queue_storage", "table_storage", "data_lake_storage"]
test_e2e = ["storage_account", "blob_storage", "queue_storage", "table_storage", "data_lake_storage"]
storage_account = []
azurite_workaround = []
blob = []
queue = []
table = []
data_lake = []
blob_storage = []
queue_storage = []
table_storage = []
data_lake_storage = []



# This section specifies the required features for the examples.

[[example]]
name="table_00"
required-features = ["table_storage"]

MindFlavor marked this conversation as resolved.
Show resolved Hide resolved



[[example]]
name="account00"
required-features = ["storage_account"]




[[example]]
name="blob_00"
required-features=["blob_storage"]

[[example]]
name="blob_01"
required-features=["blob_storage"]

[[example]]
name="blob_02_bearer_token"
required-features=["blob_storage"]

[[example]]
name="blob_04"
required-features=["blob_storage"]

[[example]]
name="blob_05_default_credential"
required-features=["blob_storage"]

[[example]]
name="blob_range"
required-features=["blob_storage"]

[[example]]
name="connection_string_builder"
required-features=["blob_storage"]

[[example]]
name="connection_string"
required-features=["blob_storage"]

[[example]]
name="container_00"
required-features=["blob_storage"]

[[example]]
name="container_01"
required-features=["blob_storage"]

[[example]]
name="container_and_blob"
required-features=["blob_storage"]

[[example]]
name="copy_blob_from_url"
required-features=["blob_storage"]

[[example]]
name="copy_blob"
required-features=["blob_storage"]

[[example]]
name="count_blobs"
required-features=["blob_storage"]

[[example]]
name="emulator_00"
required-features=["blob_storage"]

[[example]]
name="list_blobs_00"
required-features=["blob_storage"]

[[example]]
name="list_blobs_01"
required-features=["blob_storage"]

[[example]]
name="list_containers2"
required-features=["blob_storage"]

[[example]]
name="put_append_blob_00"
required-features=["blob_storage"]

[[example]]
name="put_block_blob_00"
required-features=["blob_storage"]

[[example]]
name="put_page_blob_00"
required-features=["blob_storage"]

#[[example]]
MindFlavor marked this conversation as resolved.
Show resolved Hide resolved
#name="sas00"
#required-features=["blob_storage"]

[[example]]
name="shared_access_signature"
required-features=["blob_storage"]

[[example]]
name="stream_blob_00"
required-features=["blob_storage"]

[[example]]
name="stream_blob_01"
required-features=["blob_storage"]




[[example]]
name="list_queues"
required-features=["queue_storage"]

[[example]]
name="queue_create"
required-features=["queue_storage"]

[[example]]
name="get_messages"
required-features=["queue_storage"]

[[example]]
name="peek_messages"
required-features=["queue_storage"]

[[example]]
name="delete_message"
required-features=["queue_storage"]

[[example]]
name="put_message"
required-features=["queue_storage"]




[[example]]
name="data_lake_00"
required-features=["data_lake_storage"]
3 changes: 2 additions & 1 deletion sdk/storage/examples/blob_00.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[macro_use]
extern crate log;
use azure_core::prelude::*;
use azure_storage::clients::*;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use futures::stream::StreamExt;
use std::error::Error;
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/examples/blob_01.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use azure_core::prelude::*;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use std::error::Error;
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/examples/blob_02_bearer_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate log;

use azure_core::prelude::*;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use std::error::Error;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/examples/blob_04.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use azure_core::prelude::*;
use azure_storage::blob::prelude::*;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use bytes::{BufMut, Bytes};
use std::error::Error;
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/examples/blob_05_default_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate log;
use azure_core::prelude::*;
use azure_core::TokenCredential;
use azure_identity::token_credentials::DefaultCredential;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use std::error::Error;
use std::sync::Arc;
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/examples/blob_range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use azure_core::prelude::*;
use azure_storage::blob_storage::prelude::*;
use azure_storage::core::prelude::*;
use futures::stream::StreamExt;
use std::error::Error;
Expand Down
30 changes: 0 additions & 30 deletions sdk/storage/examples/box.rs

This file was deleted.

Loading