From 088800d3345f3443c3d406f0603675e000d190e5 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 8 May 2023 20:12:46 +0800 Subject: [PATCH] feat: Add assert for public types to make sure Send + Sync Signed-off-by: Xuanwo --- core/src/lib.rs | 14 ++++++++++++++ core/src/raw/oio/page.rs | 2 +- core/src/types/list.rs | 10 ++++++++++ core/src/types/writer.rs | 5 +++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 3cf0229e0ce6..eb888d6ad070 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -94,4 +94,18 @@ mod tests { assert_eq!(1, size_of::()); assert_eq!(24, size_of::()); } + + /// This is used to make sure our public API implement Send + Sync + trait AssertSendSync: Send + Sync {} + impl AssertSendSync for Entry {} + impl AssertSendSync for Capability {} + impl AssertSendSync for Error {} + impl AssertSendSync for Reader {} + impl AssertSendSync for Writer {} + impl AssertSendSync for Lister {} + impl AssertSendSync for Operator {} + impl AssertSendSync for BlockingReader {} + impl AssertSendSync for BlockingWriter {} + impl AssertSendSync for BlockingLister {} + impl AssertSendSync for BlockingOperator {} } diff --git a/core/src/raw/oio/page.rs b/core/src/raw/oio/page.rs index cf21a5e766a2..9dd833de3799 100644 --- a/core/src/raw/oio/page.rs +++ b/core/src/raw/oio/page.rs @@ -96,7 +96,7 @@ impl Page for Option

{ } /// BlockingPage is the blocking version of [`Page`]. -pub trait BlockingPage: 'static { +pub trait BlockingPage: Send + 'static { /// Fetch a new page of [`Entry`] /// /// `Ok(None)` means all pages have been returned. Any following call diff --git a/core/src/types/list.rs b/core/src/types/list.rs index 708effae6470..275a76db7690 100644 --- a/core/src/types/list.rs +++ b/core/src/types/list.rs @@ -47,6 +47,11 @@ pub struct Lister { fut: Option>>)>>, } +/// # Safety +/// +/// Lister will only be accessed by `&mut Self` +unsafe impl Sync for Lister {} + impl Lister { /// Create a new lister. pub(crate) fn new(pager: oio::Pager) -> Self { @@ -166,6 +171,11 @@ pub struct BlockingLister { buf: VecDeque, } +/// # Safety +/// +/// BlockingLister will only be accessed by `&mut Self` +unsafe impl Sync for BlockingLister {} + impl BlockingLister { /// Create a new lister. pub(crate) fn new(pager: oio::BlockingPager) -> Self { diff --git a/core/src/types/writer.rs b/core/src/types/writer.rs index e709dba36179..bb6adc1b7db8 100644 --- a/core/src/types/writer.rs +++ b/core/src/types/writer.rs @@ -58,6 +58,11 @@ pub struct Writer { state: State, } +/// # Safety +/// +/// Writer will only be accessed by `&mut Self` +unsafe impl Sync for Writer {} + impl Writer { /// Create a new writer. ///