Skip to content

Commit

Permalink
Make SHM Alloc builders naming more friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Sep 16, 2024
1 parent 53ad313 commit 4ad1ef6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
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

0 comments on commit 4ad1ef6

Please sign in to comment.