提交 03d300fc authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Move transport cloning into private module to make it unreachable externally

上级 ce31fb42
...@@ -40,6 +40,27 @@ uuid_based_wrapper_type!( ...@@ -40,6 +40,27 @@ uuid_based_wrapper_type!(
TransportId TransportId
); );
// We don't want this to be a public API, but have to use it like this to be able to still use as
// trait object
mod private {
use super::Transport;
#[doc(hidden)]
pub trait CloneTransport {
#[doc(hidden)]
fn clone_box(&self) -> Box<dyn Transport>;
}
impl<T> CloneTransport for T
where
T: Transport + Clone + 'static,
{
fn clone_box(&self) -> Box<dyn Transport> {
Box::new(self.clone())
}
}
}
/// Data contained in transport trace events. /// Data contained in transport trace events.
/// ///
/// See also "trace" event in the [Debugging](https://mediasoup.org/documentation/v3/mediasoup/debugging#trace-Event) /// See also "trace" event in the [Debugging](https://mediasoup.org/documentation/v3/mediasoup/debugging#trace-Event)
...@@ -128,7 +149,7 @@ pub(super) enum TransportType { ...@@ -128,7 +149,7 @@ pub(super) enum TransportType {
/// ///
/// For additional methods see [`TransportGeneric`]. /// For additional methods see [`TransportGeneric`].
#[async_trait(?Send)] #[async_trait(?Send)]
pub trait Transport: Debug + Send + Sync + CloneTransport { pub trait Transport: Debug + Send + Sync + private::CloneTransport {
/// Transport id. /// Transport id.
#[must_use] #[must_use]
fn id(&self) -> TransportId; fn id(&self) -> TransportId;
...@@ -253,28 +274,9 @@ pub trait Transport: Debug + Send + Sync + CloneTransport { ...@@ -253,28 +274,9 @@ pub trait Transport: Debug + Send + Sync + CloneTransport {
fn on_close(&self, callback: Box<dyn FnOnce() + Send + 'static>) -> HandlerId; fn on_close(&self, callback: Box<dyn FnOnce() + Send + 'static>) -> HandlerId;
} }
// We don't want this to be a public API, but have to use it like this to be able to still use as
// trait object
/// This is a private method, don't use it outside of the library
#[doc(hidden)]
pub trait CloneTransport {
/// This is a private method, don't use it outside of the library
#[doc(hidden)]
fn clone_transport(&self) -> Box<dyn Transport>;
}
impl<T> CloneTransport for T
where
T: Transport + Clone + 'static,
{
fn clone_transport(&self) -> Box<dyn Transport> {
Box::new(self.clone())
}
}
impl Clone for Box<dyn Transport> { impl Clone for Box<dyn Transport> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
self.clone_transport() self.clone_box()
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论