-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These constructors don't expose the internal `Bytes` type, but instead will try to downcast the argument to prevent a copy. If the types don't match up (a user provides an older version of `Bytes`), the value will just be copied. Adds: - `HeaderValue::from_maybe_shared` - `HeaderValue::from_maybe_shared_unchecked` - `Uri::from_maybe_shared` - `Authority::from_maybe_shared` - `PathAndQuery::from_maybe_shared`
- Loading branch information
1 parent
efa7fe0
commit 566878e
Showing
7 changed files
with
114 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
macro_rules! if_downcast_into { | ||
($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`. | ||
let mut slot = Some($val); | ||
// Re-write the `$val` ident with the downcasted value. | ||
let $val = (&mut slot as &mut dyn std::any::Any) | ||
.downcast_mut::<Option<$out_ty>>() | ||
.unwrap() | ||
.take() | ||
.unwrap(); | ||
// Run the $body in scope of the replaced val. | ||
$body | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters