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

partial format the code and fix typo and modernize #597

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/byte_str.rs
Expand Up @@ -43,7 +43,7 @@ impl ByteStr {
}
}
// Invariant: assumed by the safety requirements of this function.
ByteStr { bytes: bytes }
ByteStr { bytes }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/convert.rs
@@ -1,5 +1,5 @@
macro_rules! if_downcast_into {
($in_ty:ty, $out_ty:ty, $val:ident, $body:expr) => ({
($in_ty:ty, $out_ty:ty, $val:ident, $body:expr) => {{
if std::any::TypeId::of::<$in_ty>() == std::any::TypeId::of::<$out_ty>() {
// Store the value in an `Option` so we can `take`
// it after casting to `&mut dyn Any`.
Expand All @@ -13,5 +13,5 @@ macro_rules! if_downcast_into {
// Run the $body in scope of the replaced val.
$body
}
})
}};
}
18 changes: 7 additions & 11 deletions src/extensions.rs
Expand Up @@ -61,7 +61,7 @@ impl Extensions {
/// ```
pub fn insert<T: Send + Sync + 'static>(&mut self, val: T) -> Option<T> {
self.map
.get_or_insert_with(|| Box::new(HashMap::default()))
.get_or_insert_with(Default::default)
.insert(TypeId::of::<T>(), Box::new(val))
.and_then(|boxed| {
(boxed as Box<dyn Any + 'static>)
Expand Down Expand Up @@ -166,9 +166,7 @@ impl Extensions {
/// ```
#[inline]
pub fn is_empty(&self) -> bool {
self.map
.as_ref()
.map_or(true, |map| map.is_empty())
self.map.as_ref().map_or(true, |map| map.is_empty())
}

/// Get the numer of extensions available.
Expand All @@ -184,28 +182,26 @@ impl Extensions {
/// ```
#[inline]
pub fn len(&self) -> usize {
self.map
.as_ref()
.map_or(0, |map| map.len())
self.map.as_ref().map_or(0, |map| map.len())
}

/// Extends `self` with another `Extensions`.
///
/// If an instance of a specific type exists in both, the one in `self` is overwritten with the
/// one from `other`.
///
///
/// # Example
///
///
/// ```
/// # use http::Extensions;
/// let mut ext_a = Extensions::new();
/// ext_a.insert(8u8);
/// ext_a.insert(16u16);
///
///
/// let mut ext_b = Extensions::new();
/// ext_b.insert(4u8);
/// ext_b.insert("hello");
///
///
/// ext_a.extend(ext_b);
/// assert_eq!(ext_a.len(), 3);
/// assert_eq!(ext_a.get::<u8>(), Some(&4u8));
Expand Down