diff --git a/iceoryx2-bb/elementary/src/generic_pointer.rs b/iceoryx2-bb/elementary/src/generic_pointer.rs new file mode 100644 index 000000000..7d166e16c --- /dev/null +++ b/iceoryx2-bb/elementary/src/generic_pointer.rs @@ -0,0 +1,19 @@ +// Copyright (c) 2024 Contributors to the Eclipse Foundation +// +// See the NOTICE file(s) distributed with this work for additional +// information regarding copyright ownership. +// +// This program and the accompanying materials are made available under the +// terms of the Apache Software License 2.0 which is available at +// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license +// which is available at https://opensource.org/licenses/MIT. +// +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use crate::pointer_trait::PointerTrait; + +/// Trait that allows to use typed pointers as generic arguments for structs. +pub trait GenericPointer { + /// The underlying pointer type. + type Type: PointerTrait; +} diff --git a/iceoryx2-bb/elementary/src/lib.rs b/iceoryx2-bb/elementary/src/lib.rs index 3b1bfb0df..e55db7c28 100644 --- a/iceoryx2-bb/elementary/src/lib.rs +++ b/iceoryx2-bb/elementary/src/lib.rs @@ -19,6 +19,7 @@ pub mod enum_gen; pub mod alignment; pub mod allocator; pub mod bump_allocator; +pub mod generic_pointer; pub mod lazy_singleton; pub mod math; pub mod owning_pointer; diff --git a/iceoryx2-bb/elementary/src/owning_pointer.rs b/iceoryx2-bb/elementary/src/owning_pointer.rs index 5194cd0b3..f1f6f5f13 100644 --- a/iceoryx2-bb/elementary/src/owning_pointer.rs +++ b/iceoryx2-bb/elementary/src/owning_pointer.rs @@ -16,8 +16,11 @@ use std::alloc::Layout; use std::alloc::{alloc, dealloc}; +use crate::generic_pointer::GenericPointer; use crate::pointer_trait::PointerTrait; +pub struct GenericOwningPointer; + /// Representation of a pointer which owns its memory. #[repr(C)] #[derive(Debug)] @@ -63,3 +66,7 @@ impl PointerTrait for OwningPointer { self.ptr } } + +impl GenericPointer for GenericOwningPointer { + type Type = OwningPointer; +} diff --git a/iceoryx2-bb/elementary/src/relocatable_ptr.rs b/iceoryx2-bb/elementary/src/relocatable_ptr.rs index 146a0a9c9..d4e48d6a4 100644 --- a/iceoryx2-bb/elementary/src/relocatable_ptr.rs +++ b/iceoryx2-bb/elementary/src/relocatable_ptr.rs @@ -64,10 +64,13 @@ //! } //! ``` +use crate::generic_pointer::GenericPointer; pub use crate::pointer_trait::PointerTrait; use iceoryx2_pal_concurrency_sync::iox_atomic::IoxAtomicIsize; use std::{marker::PhantomData, ptr::NonNull}; +pub struct GenericRelocatablePointer; + /// A [`RelocatablePointer`] stores only the distance from its memory starting position to the /// memory location it is pointing to. When the [`RelocatablePointer`] is now shared between /// processes its virtual memory starting position changes but the distance to the object it is @@ -138,3 +141,7 @@ impl PointerTrait for RelocatablePointer { self.as_ptr() as *mut T } } + +impl GenericPointer for GenericRelocatablePointer { + type Type = RelocatablePointer; +}