Skip to content

Commit

Permalink
Massive renaming for ZSliceShm and ZSliceShmMut
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Apr 30, 2024
1 parent 0c399ec commit bca2fd7
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
//

pub mod traits;
pub mod zsliceshm;
pub mod zsliceshmmut;
pub mod zshm;
pub mod zshmmut;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,81 @@ use zenoh_buffers::{ZBuf, ZSlice};

use crate::SharedMemoryBuf;

use super::{traits::SHMBuf, zsliceshmmut::zsliceshmmut};
use super::{traits::SHMBuf, zshmmut::zshmmut};

/// An immutable SHM slice
/// An immutable SHM buffer
#[zenoh_macros::unstable_doc]
#[repr(transparent)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ZSliceShm(pub(crate) SharedMemoryBuf);
pub struct ZShm(pub(crate) SharedMemoryBuf);

impl SHMBuf for ZSliceShm {
impl SHMBuf for ZShm {
fn is_valid(&self) -> bool {
self.0.is_valid()
}
}

impl PartialEq<&zsliceshm> for ZSliceShm {
fn eq(&self, other: &&zsliceshm) -> bool {
impl PartialEq<&zshm> for ZShm {
fn eq(&self, other: &&zshm) -> bool {
self.0 == other.0 .0
}
}

impl Borrow<zsliceshm> for ZSliceShm {
fn borrow(&self) -> &zsliceshm {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl Borrow<zshm> for ZShm {
fn borrow(&self) -> &zshm {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl BorrowMut<zsliceshm> for ZSliceShm {
fn borrow_mut(&mut self) -> &mut zsliceshm {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl BorrowMut<zshm> for ZShm {
fn borrow_mut(&mut self) -> &mut zshm {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl Deref for ZSliceShm {
impl Deref for ZShm {
type Target = [u8];

fn deref(&self) -> &Self::Target {
self.0.as_ref()
}
}

impl AsRef<[u8]> for ZSliceShm {
impl AsRef<[u8]> for ZShm {
fn as_ref(&self) -> &[u8] {
self
}
}

impl From<SharedMemoryBuf> for ZSliceShm {
impl From<SharedMemoryBuf> for ZShm {
fn from(value: SharedMemoryBuf) -> Self {
Self(value)
}
}

impl From<ZSliceShm> for ZSlice {
fn from(value: ZSliceShm) -> Self {
impl From<ZShm> for ZSlice {
fn from(value: ZShm) -> Self {
value.0.into()
}
}

impl From<ZSliceShm> for ZBuf {
fn from(value: ZSliceShm) -> Self {
impl From<ZShm> for ZBuf {
fn from(value: ZShm) -> Self {
value.0.into()
}
}

impl TryFrom<&mut ZSliceShm> for &mut zsliceshmmut {
impl TryFrom<&mut ZShm> for &mut zshmmut {
type Error = ();

fn try_from(value: &mut ZSliceShm) -> Result<Self, Self::Error> {
fn try_from(value: &mut ZShm) -> Result<Self, Self::Error> {
match value.0.is_unique() && value.0.is_valid() {
true => {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
Ok(unsafe { core::mem::transmute(value) })
}
Expand All @@ -105,64 +105,64 @@ impl TryFrom<&mut ZSliceShm> for &mut zsliceshmmut {
}
}

/// A borrowed immutable SHM slice
/// A borrowed immutable SHM buffer
#[zenoh_macros::unstable_doc]
#[derive(Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
#[repr(transparent)]
pub struct zsliceshm(ZSliceShm);
pub struct zshm(ZShm);

impl ToOwned for zsliceshm {
type Owned = ZSliceShm;
impl ToOwned for zshm {
type Owned = ZShm;

fn to_owned(&self) -> Self::Owned {
self.0.clone()
}
}

impl PartialEq<ZSliceShm> for &zsliceshm {
fn eq(&self, other: &ZSliceShm) -> bool {
impl PartialEq<ZShm> for &zshm {
fn eq(&self, other: &ZShm) -> bool {
self.0 .0 == other.0
}
}

impl Deref for zsliceshm {
type Target = ZSliceShm;
impl Deref for zshm {
type Target = ZShm;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for zsliceshm {
impl DerefMut for zshm {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl From<&SharedMemoryBuf> for &zsliceshm {
impl From<&SharedMemoryBuf> for &zshm {
fn from(value: &SharedMemoryBuf) -> Self {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(value) }
}
}

impl From<&mut SharedMemoryBuf> for &mut zsliceshm {
impl From<&mut SharedMemoryBuf> for &mut zshm {
fn from(value: &mut SharedMemoryBuf) -> Self {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(value) }
}
}

impl TryFrom<&mut zsliceshm> for &mut zsliceshmmut {
impl TryFrom<&mut zshm> for &mut zshmmut {
type Error = ();

fn try_from(value: &mut zsliceshm) -> Result<Self, Self::Error> {
fn try_from(value: &mut zshm) -> Result<Self, Self::Error> {
match value.0 .0.is_unique() && value.0 .0.is_valid() {
true => {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
Ok(unsafe { core::mem::transmute(value) })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,36 @@ use crate::SharedMemoryBuf;

use super::{
traits::{SHMBuf, SHMBufMut},
zsliceshm::{zsliceshm, ZSliceShm},
zshm::{zshm, ZShm},
};

/// A mutable SHM slice
/// A mutable SHM buffer
#[zenoh_macros::unstable_doc]
#[derive(Debug, PartialEq, Eq)]
#[repr(transparent)]
pub struct ZSliceShmMut(SharedMemoryBuf);
pub struct ZShmMut(SharedMemoryBuf);

impl SHMBuf for ZSliceShmMut {
impl SHMBuf for ZShmMut {
fn is_valid(&self) -> bool {
self.0.is_valid()
}
}

impl SHMBufMut for ZSliceShmMut {}
impl SHMBufMut for ZShmMut {}

impl ZSliceShmMut {
impl ZShmMut {
pub(crate) unsafe fn new_unchecked(data: SharedMemoryBuf) -> Self {
Self(data)
}
}

impl PartialEq<zsliceshmmut> for &ZSliceShmMut {
fn eq(&self, other: &zsliceshmmut) -> bool {
impl PartialEq<zshmmut> for &ZShmMut {
fn eq(&self, other: &zshmmut) -> bool {
self.0 == other.0 .0
}
}

impl TryFrom<SharedMemoryBuf> for ZSliceShmMut {
impl TryFrom<SharedMemoryBuf> for ZShmMut {
type Error = SharedMemoryBuf;

fn try_from(value: SharedMemoryBuf) -> Result<Self, Self::Error> {
Expand All @@ -61,126 +61,126 @@ impl TryFrom<SharedMemoryBuf> for ZSliceShmMut {
}
}

impl TryFrom<ZSliceShm> for ZSliceShmMut {
type Error = ZSliceShm;
impl TryFrom<ZShm> for ZShmMut {
type Error = ZShm;

fn try_from(value: ZSliceShm) -> Result<Self, Self::Error> {
fn try_from(value: ZShm) -> Result<Self, Self::Error> {
match value.0.is_unique() && value.0.is_valid() {
true => Ok(Self(value.0)),
false => Err(value),
}
}
}

impl Borrow<zsliceshm> for ZSliceShmMut {
fn borrow(&self) -> &zsliceshm {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl Borrow<zshm> for ZShmMut {
fn borrow(&self) -> &zshm {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl BorrowMut<zsliceshm> for ZSliceShmMut {
fn borrow_mut(&mut self) -> &mut zsliceshm {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl BorrowMut<zshm> for ZShmMut {
fn borrow_mut(&mut self) -> &mut zshm {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl Borrow<zsliceshmmut> for ZSliceShmMut {
fn borrow(&self) -> &zsliceshmmut {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl Borrow<zshmmut> for ZShmMut {
fn borrow(&self) -> &zshmmut {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl BorrowMut<zsliceshmmut> for ZSliceShmMut {
fn borrow_mut(&mut self) -> &mut zsliceshmmut {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
impl BorrowMut<zshmmut> for ZShmMut {
fn borrow_mut(&mut self) -> &mut zshmmut {
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
unsafe { core::mem::transmute(self) }
}
}

impl Deref for ZSliceShmMut {
impl Deref for ZShmMut {
type Target = [u8];

fn deref(&self) -> &Self::Target {
self.0.as_ref()
}
}

impl DerefMut for ZSliceShmMut {
impl DerefMut for ZShmMut {
fn deref_mut(&mut self) -> &mut Self::Target {
self.0.as_mut()
}
}

impl AsRef<[u8]> for ZSliceShmMut {
impl AsRef<[u8]> for ZShmMut {
fn as_ref(&self) -> &[u8] {
self
}
}

impl AsMut<[u8]> for ZSliceShmMut {
impl AsMut<[u8]> for ZShmMut {
fn as_mut(&mut self) -> &mut [u8] {
self
}
}

impl From<ZSliceShmMut> for ZSliceShm {
fn from(value: ZSliceShmMut) -> Self {
impl From<ZShmMut> for ZShm {
fn from(value: ZShmMut) -> Self {
value.0.into()
}
}

impl From<ZSliceShmMut> for ZSlice {
fn from(value: ZSliceShmMut) -> Self {
impl From<ZShmMut> for ZSlice {
fn from(value: ZShmMut) -> Self {
value.0.into()
}
}

impl From<ZSliceShmMut> for ZBuf {
fn from(value: ZSliceShmMut) -> Self {
impl From<ZShmMut> for ZBuf {
fn from(value: ZShmMut) -> Self {
value.0.into()
}
}

/// A borrowed mutable SHM slice
/// A borrowed mutable SHM buffer
#[zenoh_macros::unstable_doc]
#[derive(Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
#[repr(transparent)]
pub struct zsliceshmmut(ZSliceShmMut);
pub struct zshmmut(ZShmMut);

impl PartialEq<ZSliceShmMut> for &zsliceshmmut {
fn eq(&self, other: &ZSliceShmMut) -> bool {
impl PartialEq<ZShmMut> for &zshmmut {
fn eq(&self, other: &ZShmMut) -> bool {
self.0 .0 == other.0
}
}

impl Deref for zsliceshmmut {
type Target = ZSliceShmMut;
impl Deref for zshmmut {
type Target = ZShmMut;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl DerefMut for zsliceshmmut {
impl DerefMut for zshmmut {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl TryFrom<&mut SharedMemoryBuf> for &mut zsliceshmmut {
impl TryFrom<&mut SharedMemoryBuf> for &mut zshmmut {
type Error = ();

fn try_from(value: &mut SharedMemoryBuf) -> Result<Self, Self::Error> {
match value.is_unique() && value.is_valid() {
// SAFETY: ZSliceShm, ZSliceShmMut, zsliceshm and zsliceshmmut are #[repr(transparent)]
// SAFETY: ZShm, ZShmMut, zshm and zshmmut are #[repr(transparent)]
// to SharedMemoryBuf type, so it is safe to transmute them in any direction
true => Ok(unsafe { core::mem::transmute(value) }),
false => Err(()),
Expand Down
Loading

0 comments on commit bca2fd7

Please sign in to comment.