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

Make SHM Alloc builders naming more friendly #1421

Merged
merged 1 commit into from
Sep 16, 2024
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
48 changes: 27 additions & 21 deletions commons/zenoh-shm/src/api/provider/shm_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ where

/// Set the allocation policy
#[zenoh_macros::unstable_doc]
pub fn with_policy<Policy>(self) -> AllocBuilder2<'a, IDSource, Backend, Policy> {
AllocBuilder2 {
pub fn with_policy<Policy>(self) -> ProviderAllocBuilder<'a, IDSource, Backend, Policy> {
ProviderAllocBuilder {
data: self.0,
_phantom: PhantomData,
}
Expand All @@ -142,7 +142,7 @@ where
Backend: ShmProviderBackend,
{
fn wait(self) -> <Self as Resolvable>::To {
let builder = AllocBuilder2::<'a, IDSource, Backend, JustAlloc> {
let builder = ProviderAllocBuilder::<'a, IDSource, Backend, JustAlloc> {
data: self.0,
_phantom: PhantomData,
};
Expand Down Expand Up @@ -172,8 +172,8 @@ where
{
/// Allocate the new buffer with this layout
#[zenoh_macros::unstable_doc]
pub fn alloc(&'a self) -> AllocBuilder<'a, IDSource, Backend> {
AllocBuilder {
pub fn alloc(&'a self) -> LayoutAllocBuilder<'a, IDSource, Backend> {
LayoutAllocBuilder {
layout: self,
_phantom: PhantomData,
}
Expand Down Expand Up @@ -514,9 +514,9 @@ unsafe impl<'a, Policy: AllocPolicy, IDSource, Backend: ShmProviderBackend>
}
}*/

/// Builder for allocations
/// Builder for making allocations with instant layout calculation
#[zenoh_macros::unstable_doc]
pub struct AllocBuilder2<
pub struct ProviderAllocBuilder<
'a,
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -527,22 +527,25 @@ pub struct AllocBuilder2<
}

// Generic impl
impl<'a, IDSource, Backend, Policy> AllocBuilder2<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> ProviderAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
{
/// Set the allocation policy
#[zenoh_macros::unstable_doc]
pub fn with_policy<OtherPolicy>(self) -> AllocBuilder2<'a, IDSource, Backend, OtherPolicy> {
AllocBuilder2 {
pub fn with_policy<OtherPolicy>(
self,
) -> ProviderAllocBuilder<'a, IDSource, Backend, OtherPolicy> {
ProviderAllocBuilder {
data: self.data,
_phantom: PhantomData,
}
}
}

impl<'a, IDSource, Backend, Policy> Resolvable for AllocBuilder2<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> Resolvable
for ProviderAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -551,7 +554,7 @@ where
}

// Sync alloc policy
impl<'a, IDSource, Backend, Policy> Wait for AllocBuilder2<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> Wait for ProviderAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -569,7 +572,8 @@ where
}

// Async alloc policy
impl<'a, IDSource, Backend, Policy> IntoFuture for AllocBuilder2<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> IntoFuture
for ProviderAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend + Sync,
Expand All @@ -593,9 +597,9 @@ where
}
}

/// Builder for allocations
/// Builder for making allocations through precalculated Layout
#[zenoh_macros::unstable_doc]
pub struct AllocBuilder<
pub struct LayoutAllocBuilder<
'a,
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -606,22 +610,24 @@ pub struct AllocBuilder<
}

// Generic impl
impl<'a, IDSource, Backend, Policy> AllocBuilder<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> LayoutAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
{
/// Set the allocation policy
#[zenoh_macros::unstable_doc]
pub fn with_policy<OtherPolicy>(self) -> AllocBuilder<'a, IDSource, Backend, OtherPolicy> {
AllocBuilder {
pub fn with_policy<OtherPolicy>(
self,
) -> LayoutAllocBuilder<'a, IDSource, Backend, OtherPolicy> {
LayoutAllocBuilder {
layout: self.layout,
_phantom: PhantomData,
}
}
}

impl<'a, IDSource, Backend, Policy> Resolvable for AllocBuilder<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> Resolvable for LayoutAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -630,7 +636,7 @@ where
}

// Sync alloc policy
impl<'a, IDSource, Backend, Policy> Wait for AllocBuilder<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> Wait for LayoutAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend,
Expand All @@ -644,7 +650,7 @@ where
}

// Async alloc policy
impl<'a, IDSource, Backend, Policy> IntoFuture for AllocBuilder<'a, IDSource, Backend, Policy>
impl<'a, IDSource, Backend, Policy> IntoFuture for LayoutAllocBuilder<'a, IDSource, Backend, Policy>
where
IDSource: ProtocolIDSource,
Backend: ShmProviderBackend + Sync,
Expand Down
11 changes: 6 additions & 5 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ pub mod shm {
provider::{
chunk::{AllocatedChunk, ChunkDescriptor},
shm_provider::{
AllocBuilder, AllocBuilder2, AllocLayout, AllocLayoutSizedBuilder, AllocPolicy,
AsyncAllocPolicy, BlockOn, DeallocEldest, DeallocOptimal, DeallocYoungest,
Deallocate, Defragment, DynamicProtocolID, ForceDeallocPolicy, GarbageCollect,
JustAlloc, ProtocolIDSource, ShmProvider, ShmProviderBuilder,
ShmProviderBuilderBackendID, ShmProviderBuilderID, StaticProtocolID,
AllocLayout, AllocLayoutSizedBuilder, AllocPolicy, AsyncAllocPolicy, BlockOn,
DeallocEldest, DeallocOptimal, DeallocYoungest, Deallocate, Defragment,
DynamicProtocolID, ForceDeallocPolicy, GarbageCollect, JustAlloc,
LayoutAllocBuilder, ProtocolIDSource, ProviderAllocBuilder, ShmProvider,
ShmProviderBuilder, ShmProviderBuilderBackendID, ShmProviderBuilderID,
StaticProtocolID,
},
shm_provider_backend::ShmProviderBackend,
types::{
Expand Down
Loading