1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 17:44:56 +09:00

LibGC: Make GC::Ptr and GC::Ref formattable

This is a copy of the Formatters we have for AK's pointer types.
This commit is contained in:
Sam Atkins 2025-04-24 14:05:30 +01:00
parent 60bd5012fe
commit 06d62e5b5a
Notes: github-actions[bot] 2025-05-01 16:17:13 +00:00

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/Format.h>
#include <AK/Traits.h>
#include <AK/Types.h>
@ -238,4 +239,29 @@ struct Traits<GC::Ref<T>> : public DefaultTraits<GC::Ref<T>> {
}
};
template<typename T>
struct Formatter<GC::Ptr<T>> : Formatter<T const*> {
ErrorOr<void> format(FormatBuilder& builder, GC::Ptr<T> const& value)
{
return Formatter<T const*>::format(builder, value.ptr());
}
};
template<Formattable T>
struct Formatter<GC::Ref<T>> : Formatter<T> {
ErrorOr<void> format(FormatBuilder& builder, GC::Ref<T> const& value)
{
return Formatter<T>::format(builder, *value);
}
};
template<typename T>
requires(!HasFormatter<T>)
struct Formatter<GC::Ref<T>> : Formatter<T const*> {
ErrorOr<void> format(FormatBuilder& builder, GC::Ref<T> const& value)
{
return Formatter<T const*>::format(builder, value.ptr());
}
};
}