mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 12:20:00 +01: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:
parent
60bd5012fe
commit
06d62e5b5a
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Format.h>
|
||||||
#include <AK/Traits.h>
|
#include <AK/Traits.h>
|
||||||
#include <AK/Types.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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user