Skip to content

Commit

Permalink
Turbopack: impl<T: ValueDebugFormat> Value<T> (#69961)
Browse files Browse the repository at this point in the history
Now you can do `x.dbg().await?` not only for `Vc<T>` but also
`Value<T>`.
  • Loading branch information
mischnic authored Sep 11, 2024
1 parent 3d303a1 commit 422a086
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion turbopack/crates/turbo-tasks/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::{fmt::Debug, marker::PhantomData, ops::Deref};

use anyhow::Result;
use serde::{Deserialize, Serialize};

use crate::SharedReference;
use crate::{
debug::{ValueDebugFormat, ValueDebugString},
ReadRef, SharedReference,
};

/// Pass a value by value (`Value<Xxx>`) instead of by reference (`Vc<Xxx>`).
///
Expand Down Expand Up @@ -38,6 +42,20 @@ impl<T: Default> Default for Value<T> {
}
}

impl<T: ValueDebugFormat> Value<T> {
pub async fn dbg(&self) -> Result<ReadRef<ValueDebugString>> {
self.dbg_depth(usize::MAX).await
}

pub async fn dbg_depth(&self, depth: usize) -> Result<ReadRef<ValueDebugString>> {
self.inner
.value_debug_format(depth)
.try_to_value_debug_string()
.await?
.await
}
}

/// Pass a value by value (`Value<Xxx>`) instead of by reference (`Vc<Xxx>`).
///
/// Doesn't require serialization, and won't be stored in the persistent cache
Expand Down

0 comments on commit 422a086

Please # to comment.