Skip to content

Commit

Permalink
Use derived impl with bound = "" instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Sep 19, 2024
1 parent 1fbedd5 commit e6ed35b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
23 changes: 2 additions & 21 deletions turbopack/crates/turbo-tasks/src/vc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ use crate::{
/// some_ref.some_method_on_t();
/// ```
#[must_use]
#[derive(Serialize, Deserialize)]
#[serde(transparent, bound = "")]
pub struct Vc<T>
where
T: ?Sized + Send,
Expand Down Expand Up @@ -231,27 +233,6 @@ where

impl<T> Eq for Vc<T> where T: ?Sized + Send {}

impl<T> Serialize for Vc<T>
where
T: ?Sized + Send,
{
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.node.serialize(serializer)
}
}

impl<'de, T> Deserialize<'de> for Vc<T>
where
T: ?Sized + Send,
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(Vc {
node: RawVc::deserialize(deserializer)?,
_t: PhantomData,
})
}
}

// TODO(alexkirsz) This should not be implemented for Vc. Instead, users should
// use the `ValueDebug` implementation to get a `D: Debug`.
impl<T> std::fmt::Debug for Vc<T>
Expand Down
22 changes: 2 additions & 20 deletions turbopack/crates/turbo-tasks/src/vc/resolved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use crate::{
RcStr, VcRead, VcTransparentRead, VcValueType,
};

#[derive(Serialize, Deserialize)]
#[serde(transparent, bound = "")]
pub struct ResolvedVc<T>
where
T: ?Sized + Send,
Expand Down Expand Up @@ -140,26 +142,6 @@ where
}
}

impl<T> Serialize for ResolvedVc<T>
where
T: ?Sized + Send,
{
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.node.serialize(serializer)
}
}

impl<'de, T> Deserialize<'de> for ResolvedVc<T>
where
T: ?Sized + Send,
{
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(ResolvedVc {
node: Vc::deserialize(deserializer)?,
})
}
}

/// Indicates that a type does not contain any instances of [`Vc`]. It may
/// contain [`ResolvedVc`].
///
Expand Down

0 comments on commit e6ed35b

Please sign in to comment.