Skip to content

Commit

Permalink
feat(core): deprecate upgrade::from_fn
Browse files Browse the repository at this point in the history
This functionality isn't needed anywhere in `rust-libp2p` so we can deprecate and later remove it and thus reduce our API surface. Users relying on this function can vendor it.

Pull-Request: #3747.
  • Loading branch information
thomaseizinger authored Apr 19, 2023
1 parent 5df321d commit 0fe9791
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.39.2 - unreleased

- Deprecate `upgrade::from_fn` without replacement as it is not used within `rust-libp2p`.
If you depend on it, we suggest you vendor it.
See [PR 3747].

[PR 3747]: https://github.com/libp2p/rust-libp2p/pull/3747

## 0.39.1

- Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312].
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021"
rust-version = "1.60.0"
description = "Core traits and structs of libp2p"
version = "0.39.1"
version = "0.39.2"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
3 changes: 2 additions & 1 deletion core/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ mod transfer;

use futures::future::Future;

#[allow(deprecated)]
pub use self::from_fn::{from_fn, FromFnUpgrade};
pub use self::{
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
denied::DeniedUpgrade,
error::UpgradeError,
from_fn::{from_fn, FromFnUpgrade},
map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr},
optional::OptionalUpgrade,
pending::PendingUpgrade,
Expand Down
11 changes: 11 additions & 0 deletions core/src/upgrade/from_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::iter;
/// # use libp2p_core::{upgrade, Negotiated};
/// # use std::io;
/// # use futures::AsyncWriteExt;
/// # #[allow(deprecated)]
/// let _transport = MemoryTransport::default()
/// .and_then(move |out, cp| {
/// upgrade::apply(out, upgrade::from_fn("/foo/1", move |mut sock: Negotiated<Channel<Vec<u8>>>, endpoint| async move {
Expand All @@ -52,6 +53,10 @@ use std::iter;
/// });
/// ```
///
#[deprecated(
note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`."
)]
#[allow(deprecated)]
pub fn from_fn<P, F, C, Fut, Out, Err>(protocol_name: P, fun: F) -> FromFnUpgrade<P, F>
where
// Note: these bounds are there in order to help the compiler infer types
Expand All @@ -66,11 +71,15 @@ where
///
/// The upgrade consists in calling the function passed when creating this struct.
#[derive(Debug, Clone)]
#[deprecated(
note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`."
)]
pub struct FromFnUpgrade<P, F> {
protocol_name: P,
fun: F,
}

#[allow(deprecated)]
impl<P, F> UpgradeInfo for FromFnUpgrade<P, F>
where
P: ProtocolName + Clone,
Expand All @@ -83,6 +92,7 @@ where
}
}

#[allow(deprecated)]
impl<C, P, F, Fut, Err, Out> InboundUpgrade<C> for FromFnUpgrade<P, F>
where
P: ProtocolName + Clone,
Expand All @@ -98,6 +108,7 @@ where
}
}

#[allow(deprecated)]
impl<C, P, F, Fut, Err, Out> OutboundUpgrade<C> for FromFnUpgrade<P, F>
where
P: ProtocolName + Clone,
Expand Down

0 comments on commit 0fe9791

Please sign in to comment.