Skip to content

Commit

Permalink
Cleanup core (#162)
Browse files Browse the repository at this point in the history
* Remove Yes,No,ToAssign

* Remove unused traits from core

* Compiles with all features

* Small cleanup

* Move to request_options sub module

* Move things around

* Don't make module pub(crate)

* Missed some formatting

* Fix test

* Small changes

* Fix compilation issues
  • Loading branch information
rylev authored Feb 8, 2021
1 parent 6ad6dd5 commit 606a99e
Show file tree
Hide file tree
Showing 79 changed files with 475 additions and 1,177 deletions.
7 changes: 6 additions & 1 deletion sdk/core/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::range::ParseError;
use http::header::ToStrError;
use hyper::{self, body, Body, StatusCode};
use std::io::Error as IOError;
Expand All @@ -15,6 +14,12 @@ pub enum ParsingError {
ElementNotFound(String),
}

#[derive(Debug, Clone, PartialEq)]
pub enum ParseError {
SplitNotFound,
ParseIntError(ParseIntError),
}

quick_error! {
#[derive(Debug)]
pub enum AzurePathParseError {
Expand Down
52 changes: 26 additions & 26 deletions sdk/core/src/headers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
mod utilities;

use http::request::Builder;

pub use hyper::header::{IF_MODIFIED_SINCE, USER_AGENT};
pub use utilities::*;

pub const MS_DATE: &str = "x-ms-date";

pub trait AddAsHeader {
fn add_as_header(&self, builder: Builder) -> Builder;
}

#[must_use]
pub fn add_optional_header_ref<T: crate::AddAsHeader>(
item: &Option<&T>,
mut builder: Builder,
) -> Builder {
pub fn add_optional_header_ref<T: AddAsHeader>(item: &Option<&T>, mut builder: Builder) -> Builder {
if let Some(item) = item {
builder = item.add_as_header(builder);
}
builder
}

#[must_use]
pub fn add_optional_header<T: crate::AddAsHeader>(
item: &Option<T>,
mut builder: Builder,
) -> Builder {
pub fn add_optional_header<T: AddAsHeader>(item: &Option<T>, mut builder: Builder) -> Builder {
if let Some(item) = item {
builder = item.add_as_header(builder);
}
builder
}

#[must_use]
pub fn add_mandatory_header<T: crate::AddAsHeader>(item: &T, builder: Builder) -> Builder {
pub fn add_mandatory_header<T: AddAsHeader>(item: &T, builder: Builder) -> Builder {
item.add_as_header(builder)
}

pub const SERVER: &str = "server"; // -> [String]
pub const SERVER: &str = "server";
pub const SOURCE_IF_MODIFIED_SINCE: &str = "x-ms-source-if-modified-since";
pub const SOURCE_IF_UNMODIFIED_SINCE: &str = "x-ms-source-if-unmodified-since";
pub const SOURCE_IF_MATCH: &str = "x-ms-source-if-match";
pub const SOURCE_IF_NONE_MATCH: &str = "x-ms-source-if-none-match";
pub const RANGE_GET_CONTENT_MD5: &str = "x-ms-range-get-content-md5"; //=> [bool] }
pub const LEASE_ID: &str = "x-ms-lease-id"; //=> [LeaseId] }
pub const SOURCE_LEASE_ID: &str = "x-ms-source-lease-id"; //=> [LeaseId] }
pub const CLIENT_REQUEST_ID: &str = "x-ms-client-request-id"; //=> [String] }
pub const BLOB_PUBLIC_ACCESS: &str = "x-ms-blob-public-access"; // [PublicAccess]
pub const REQUEST_ID: &str = "x-ms-request-id"; //=> [String] }
pub const LEASE_STATUS: &str = "x-ms-lease-status"; //=> [LeaseStatus] }
pub const LEASE_STATE: &str = "x-ms-lease-state"; //=> [LeaseState] }
pub const LEASE_DURATION: &str = "x-ms-lease-duration"; //=> [LeaseDuration] }
pub const RANGE_GET_CONTENT_MD5: &str = "x-ms-range-get-content-md5";
pub const LEASE_ID: &str = "x-ms-lease-id";
pub const SOURCE_LEASE_ID: &str = "x-ms-source-lease-id";
pub const CLIENT_REQUEST_ID: &str = "x-ms-client-request-id";
pub const BLOB_PUBLIC_ACCESS: &str = "x-ms-blob-public-access";
pub const REQUEST_ID: &str = "x-ms-request-id";
pub const LEASE_STATUS: &str = "x-ms-lease-status";
pub const LEASE_STATE: &str = "x-ms-lease-state";
pub const LEASE_DURATION: &str = "x-ms-lease-duration";
pub const HAS_IMMUTABILITY_POLICY: &str = "x-ms-has-immutability-policy";
pub const HAS_LEGAL_HOLD: &str = "x-ms-has-legal-hold";
pub const META_PREFIX: &str = "x-ms-meta-";
pub const LEASE_ACTION: &str = "x-ms-lease-action"; //=> [LeaseAction] }
pub const LEASE_BREAK_PERIOD: &str = "x-ms-lease-break-period"; //=> [u32] }
pub const PROPOSED_LEASE_ID: &str = "x-ms-proposed-lease-id"; //=> [LeaseId] }
pub const LEASE_ACTION: &str = "x-ms-lease-action";
pub const LEASE_BREAK_PERIOD: &str = "x-ms-lease-break-period";
pub const PROPOSED_LEASE_ID: &str = "x-ms-proposed-lease-id";
pub const LEASE_TIME: &str = "x-ms-lease-time";
pub const CREATION_TIME: &str = "x-ms-creation-time";
pub const COPY_ID: &str = "x-ms-copy-id";
Expand All @@ -60,8 +60,8 @@ pub const COPY_COMPLETION_TIME: &str = "x-ms-copy-completion-time";
pub const COPY_PROGRESS: &str = "x-ms-copy-progress";
pub const COPY_SOURCE: &str = "x-ms-copy-source";
pub const COPY_STATUS: &str = "x-ms-copy-status";
pub const CONTENT_MD5: &str = "Content-MD5"; //=> [String] }
pub const SOURCE_CONTENT_MD5: &str = "x-ms-source-content-md5"; //=> [String] }
pub const CONTENT_MD5: &str = "Content-MD5";
pub const SOURCE_CONTENT_MD5: &str = "x-ms-source-content-md5";
pub const SERVER_ENCRYPTED: &str = "x-ms-server-encrypted";
pub const BLOB_TYPE: &str = "x-ms-blob-type";
pub const CONTENT_CRC64: &str = "x-ms-content-crc64";
Expand All @@ -85,5 +85,5 @@ pub const CONTINUATION: &str = "x-ms-continuation";
pub const SESSION_TOKEN: &str = "x-ms-session-token";
pub const REQUIRES_SYNC: &str = "x-ms-requires-sync";
pub const VERSION: &str = "x-ms-version";
pub const PROPERTIES: &str = "x-ms-properties"; //=> [String] }
pub const NAMESPACE_ENABLED: &str = "x-ms-namespace-enabled"; //=> [String] }
pub const PROPERTIES: &str = "x-ms-properties";
pub const NAMESPACE_ENABLED: &str = "x-ms-namespace-enabled";
2 changes: 1 addition & 1 deletion sdk/core/src/headers/utilities.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::errors::{check_status_extract_body_2, AzureError};
use crate::lease::LeaseId;
use crate::request_options::LeaseId;
use crate::util::HeaderMapExt;
use crate::{Consistency, RequestId, SessionToken};
use chrono::{DateTime, Utc};
Expand Down
2 changes: 0 additions & 2 deletions sdk/core/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub trait HttpClient: Send + Sync + std::fmt::Debug {
}
}

pub static EMPTY_BODY: &[u8; 0] = &[];

#[async_trait]
impl HttpClient for hyper::Client<HttpsConnector<hyper::client::HttpConnector>> {
async fn execute_request(
Expand Down
22 changes: 9 additions & 13 deletions sdk/core/src/incompletevector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::ops::{Deref, DerefMut};

#[derive(Debug, Clone, PartialEq)]
pub struct IncompleteVector<T> {
pub next_marker: Option<NextMarker>,
pub vector: Vec<T>,
next_marker: Option<NextMarker>,
vector: Vec<T>,
}

impl<T> IncompleteVector<T> {
Expand All @@ -20,17 +20,7 @@ impl<T> IncompleteVector<T> {
}

pub fn next_marker(&self) -> Option<&NextMarker> {
if let Some(ref t) = self.next_marker.as_ref() {
Some(t)
} else {
None
}
}
}

impl<T> DerefMut for IncompleteVector<T> {
fn deref_mut(&mut self) -> &mut [T] {
&mut self.vector
self.next_marker.as_ref()
}
}

Expand All @@ -42,6 +32,12 @@ impl<T> Deref for IncompleteVector<T> {
}
}

impl<T> DerefMut for IncompleteVector<T> {
fn deref_mut(&mut self) -> &mut [T] {
&mut self.vector
}
}

#[cfg(test)]
mod test {
#[allow(unused_imports)]
Expand Down
29 changes: 0 additions & 29 deletions sdk/core/src/lease.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
use crate::headers::*;
use crate::AddAsHeader;
use http::request::Builder;
use std::str::FromStr;
use uuid::Uuid;

create_enum!(LeaseStatus, (Locked, "locked"), (Unlocked, "unlocked"));

create_enum!(
Expand All @@ -25,26 +19,3 @@ create_enum!(
(Release, "release "),
(Break, "break")
);

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LeaseId(Uuid);

impl std::fmt::Display for LeaseId {
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
self.0.fmt(fmt)
}
}

impl std::str::FromStr for LeaseId {
type Err = <Uuid as FromStr>::Err;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(uuid::Uuid::from_str(s)?))
}
}

impl AddAsHeader for LeaseId {
fn add_as_header(&self, builder: Builder) -> Builder {
builder.header(LEASE_ID, &format!("{}", self.0))
}
}
Loading

0 comments on commit 606a99e

Please sign in to comment.