feat(core): deprecate upgrade::from_fn

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.
This commit is contained in:
Thomas Eizinger
2023-04-20 00:07:42 +02:00
committed by GitHub
parent 5df321d8b9
commit 0fe9791829
5 changed files with 23 additions and 3 deletions

2
Cargo.lock generated
View File

@ -2319,7 +2319,7 @@ dependencies = [
[[package]] [[package]]
name = "libp2p-core" name = "libp2p-core"
version = "0.39.1" version = "0.39.2"
dependencies = [ dependencies = [
"async-std", "async-std",
"either", "either",

View File

@ -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 ## 0.39.1
- Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312].

View File

@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021" edition = "2021"
rust-version = "1.60.0" rust-version = "1.60.0"
description = "Core traits and structs of libp2p" description = "Core traits and structs of libp2p"
version = "0.39.1" version = "0.39.2"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT" license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p" repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -71,11 +71,12 @@ mod transfer;
use futures::future::Future; use futures::future::Future;
#[allow(deprecated)]
pub use self::from_fn::{from_fn, FromFnUpgrade};
pub use self::{ pub use self::{
apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply},
denied::DeniedUpgrade, denied::DeniedUpgrade,
error::UpgradeError, error::UpgradeError,
from_fn::{from_fn, FromFnUpgrade},
map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}, map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr},
optional::OptionalUpgrade, optional::OptionalUpgrade,
pending::PendingUpgrade, pending::PendingUpgrade,

View File

@ -35,6 +35,7 @@ use std::iter;
/// # use libp2p_core::{upgrade, Negotiated}; /// # use libp2p_core::{upgrade, Negotiated};
/// # use std::io; /// # use std::io;
/// # use futures::AsyncWriteExt; /// # use futures::AsyncWriteExt;
/// # #[allow(deprecated)]
/// let _transport = MemoryTransport::default() /// let _transport = MemoryTransport::default()
/// .and_then(move |out, cp| { /// .and_then(move |out, cp| {
/// upgrade::apply(out, upgrade::from_fn("/foo/1", move |mut sock: Negotiated<Channel<Vec<u8>>>, endpoint| async move { /// upgrade::apply(out, upgrade::from_fn("/foo/1", move |mut sock: Negotiated<Channel<Vec<u8>>>, endpoint| async move {
@ -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> pub fn from_fn<P, F, C, Fut, Out, Err>(protocol_name: P, fun: F) -> FromFnUpgrade<P, F>
where where
// Note: these bounds are there in order to help the compiler infer types // Note: these bounds are there in order to help the compiler infer types
@ -66,11 +71,15 @@ where
/// ///
/// The upgrade consists in calling the function passed when creating this struct. /// The upgrade consists in calling the function passed when creating this struct.
#[derive(Debug, Clone)] #[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> { pub struct FromFnUpgrade<P, F> {
protocol_name: P, protocol_name: P,
fun: F, fun: F,
} }
#[allow(deprecated)]
impl<P, F> UpgradeInfo for FromFnUpgrade<P, F> impl<P, F> UpgradeInfo for FromFnUpgrade<P, F>
where where
P: ProtocolName + Clone, P: ProtocolName + Clone,
@ -83,6 +92,7 @@ where
} }
} }
#[allow(deprecated)]
impl<C, P, F, Fut, Err, Out> InboundUpgrade<C> for FromFnUpgrade<P, F> impl<C, P, F, Fut, Err, Out> InboundUpgrade<C> for FromFnUpgrade<P, F>
where where
P: ProtocolName + Clone, P: ProtocolName + Clone,
@ -98,6 +108,7 @@ where
} }
} }
#[allow(deprecated)]
impl<C, P, F, Fut, Err, Out> OutboundUpgrade<C> for FromFnUpgrade<P, F> impl<C, P, F, Fut, Err, Out> OutboundUpgrade<C> for FromFnUpgrade<P, F>
where where
P: ProtocolName + Clone, P: ProtocolName + Clone,