diff --git a/crates/uv-pep508/src/marker/tree.rs b/crates/uv-pep508/src/marker/tree.rs index 55902a69a..f8c418115 100644 --- a/crates/uv-pep508/src/marker/tree.rs +++ b/crates/uv-pep508/src/marker/tree.rs @@ -1238,6 +1238,15 @@ impl MarkerTree { MarkerTreeDebugGraph { marker: self } } + /// Formats a [`MarkerTree`] in its "raw" representation. + /// + /// This is useful for debugging when one wants to look at a + /// representation of a `MarkerTree` that is precisely identical + /// to its internal representation. + pub fn debug_raw(&self) -> MarkerTreeDebugRaw<'_> { + MarkerTreeDebugRaw { marker: self } + } + fn fmt_graph(&self, f: &mut fmt::Formatter<'_>, level: usize) -> fmt::Result { match self.kind() { MarkerTreeKind::True => return write!(f, "true"), @@ -1341,6 +1350,24 @@ impl<'a> fmt::Debug for MarkerTreeDebugGraph<'a> { } } +/// Formats a [`MarkerTree`] using its raw internals. +/// +/// This is very verbose and likely only useful if you're working +/// on the internals of this crate. +/// +/// This type is created by the [`MarkerTree::debug_raw`] routine. +#[derive(Clone)] +pub struct MarkerTreeDebugRaw<'a> { + marker: &'a MarkerTree, +} + +impl<'a> fmt::Debug for MarkerTreeDebugRaw<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let node = INTERNER.shared.node(self.marker.0); + f.debug_tuple("MarkerTreeDebugRaw").field(node).finish() + } +} + /// The underlying kind of an arbitrary node in a [`MarkerTree`]. /// /// A marker tree is represented as an algebraic decision tree with two terminal nodes