[go: up one dir, main page]

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

Change Connected::connect_info to return Self #396

Merged
merged 1 commit into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
breaking change if you depend on axum with `default_features = false`. ([#286])
- **breaking:** Remove `routing::Layered` as it didn't actually do anything and
thus wasn't necessary
- **breaking:** Change `Connected::connect_info` to return `Self` and remove
the associated type `ConnectInfo` ([#396])

[#339]: https://github.com/tokio-rs/axum/pull/339
[#286]: https://github.com/tokio-rs/axum/pull/286
[#272]: https://github.com/tokio-rs/axum/pull/272
[#378]: https://github.com/tokio-rs/axum/pull/378
[#396]: https://github.com/tokio-rs/axum/pull/396

# 0.2.8 (07. October, 2021)

Expand Down
4 changes: 1 addition & 3 deletions examples/unix-domain-socket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ struct UdsConnectInfo {
}

impl connect_info::Connected<&UnixStream> for UdsConnectInfo {
type ConnectInfo = Self;

fn connect_info(target: &UnixStream) -> Self::ConnectInfo {
fn connect_info(target: &UnixStream) -> Self {
let peer_addr = target.peer_addr().unwrap();
let peer_cred = target.peer_cred().unwrap();

Expand Down
17 changes: 5 additions & 12 deletions src/extract/connect_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,13 @@ where
/// See [`Router::into_make_service_with_connect_info`] for more details.
///
/// [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info
pub trait Connected<T> {
/// The connection information type the IO resources generates.
type ConnectInfo: Clone + Send + Sync + 'static;

pub trait Connected<T>: Clone + Send + Sync + 'static {
/// Create type holding information about the connection.
fn connect_info(target: T) -> Self::ConnectInfo;
fn connect_info(target: T) -> Self;
}

impl Connected<&AddrStream> for SocketAddr {
type ConnectInfo = SocketAddr;

fn connect_info(target: &AddrStream) -> Self::ConnectInfo {
fn connect_info(target: &AddrStream) -> Self {
target.remote_addr()
}
}
Expand All @@ -86,7 +81,7 @@ where
S: Clone,
C: Connected<T>,
{
type Response = AddExtension<S, ConnectInfo<C::ConnectInfo>>;
type Response = AddExtension<S, ConnectInfo<C>>;
type Error = Infallible;
type Future = ResponseFuture<Self::Response>;

Expand Down Expand Up @@ -177,9 +172,7 @@ mod tests {
}

impl Connected<&AddrStream> for MyConnectInfo {
type ConnectInfo = Self;

fn connect_info(_target: &AddrStream) -> Self::ConnectInfo {
fn connect_info(_target: &AddrStream) -> Self {
Self {
value: "it worked!",
}
Expand Down
4 changes: 1 addition & 3 deletions src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,7 @@ impl<S> Router<S> {
/// }
///
/// impl Connected<&AddrStream> for MyConnectInfo {
/// type ConnectInfo = MyConnectInfo;
///
/// fn connect_info(target: &AddrStream) -> Self::ConnectInfo {
/// fn connect_info(target: &AddrStream) -> Self {
/// MyConnectInfo {
/// // ...
/// }
Expand Down