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:
parent
60bd5012fe
commit
06d62e5b5a
Notes:
github-actions[bot]
2025-05-01 16:17:13 +00:00
Author: https://github.com/AtkinsSJ
Commit: 06d62e5b5a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4456
Reviewed-by: https://github.com/awesomekling
1 changed files with 26 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue