Repository: servo/servo
File: components/shared/base/generic_channel/shared_memory.rs (Rust)

Code before:
                data;
                length
            ])))
        }
    }
}

impl fmt::Debug for GenericSharedMemory {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_tuple("GenericSharedMemory").finish()
    }
}

impl Serialize for GenericSharedMemory {
    fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        match &self.0 {
            GenericSharedMemoryVariant::Ipc(memory) => {
                s.serialize_newtype_variant("GenericSharedMemory", 0, "Ipc", memory)
            },
            GenericSharedMemoryVariant::InProcess(arc) => {
                if opts::get().multiprocess {
                    return Err(serde::ser::Error::custom(
                        "Arc<Vec<u8>> found in multiprocess mode!",
                    ));
                } // We know everything is in one address-space, so we can "serialize" the receiver by
                // sending a leaked Box pointer.
                let address = Arc::into_raw(arc.clone()) as *mut Vec<u8> as usize;
                s.serialize_newtype_variant("GenericSharedMemory", 1, "InProcess", &address)
            },
        }
    }
}

struct GenericSharedMemoryVisitor {}

impl<'de> serde::de::Visitor<'de> for GenericSharedMemoryVisitor {
    type Value = GenericSharedMemory;

    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("a GenericReceiver variant")
    }

    fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
    where
        A: serde::de::EnumAccess<'de>,
    {
        #[derive(Deserialize)]
        enum GenericSharedMemoryVariantNames {
            Ipc,
            InProcess,
        }

Review comment (suggestion):
```suggestion
                // sending a leaked Arc pointer.
```

Code after:
                data;
                length
            ])))
        }
    }
}

impl fmt::Debug for GenericSharedMemory {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_tuple("GenericSharedMemory").finish()
    }
}

impl Serialize for GenericSharedMemory {
    fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        match &self.0 {
            GenericSharedMemoryVariant::Ipc(memory) => {
                s.serialize_newtype_variant("GenericSharedMemory", 0, "Ipc", memory)
            },
            GenericSharedMemoryVariant::InProcess(arc) => {
                if opts::get().multiprocess || opts::get().force_ipc {
                    return Err(serde::ser::Error::custom(
                        "Arc<Vec<u8>> found in multiprocess mode!",
                    ));
                } // We know everything is in one address-space, so we can "serialize" the receiver by
                // sending a leaked Arc pointer.
                let address = Arc::into_raw(arc.clone()) as *mut Vec<u8> as usize;
                s.serialize_newtype_variant("GenericSharedMemory", 1, "InProcess", &address)
            },
        }
    }
}

struct GenericSharedMemoryVisitor {}

impl<'de> serde::de::Visitor<'de> for GenericSharedMemoryVisitor {
    type Value = GenericSharedMemory;

    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("a GenericReceiver variant")
    }

    fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
    where
        A: serde::de::EnumAccess<'de>,
    {
        #[derive(Deserialize)]
        enum GenericSharedMemoryVariantNames {
            Ipc,
            InProcess,
        }