mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
AK: Add a Stream::write_until_depleted overload for string types
All string types currently have to invoke this function as:
stream.write_until_depleted("foo"sv.bytes());
This isn't very ergonomic, but more importantly, this overload will
allow String/ByteString instances to be written in this manner once
e.g. `ByteString::view() &&` is deleted.
This commit is contained in:
committed by
Andreas Kling
parent
c7ea710b55
commit
e0bddbb65e
@@ -7,9 +7,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Concepts.h>
|
||||||
#include <AK/Error.h>
|
#include <AK/Error.h>
|
||||||
#include <AK/Format.h>
|
#include <AK/Format.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
#include <AK/StringView.h>
|
||||||
#include <AK/Traits.h>
|
#include <AK/Traits.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
@@ -47,6 +49,12 @@ public:
|
|||||||
/// contents are written or an error occurs.
|
/// contents are written or an error occurs.
|
||||||
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes);
|
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes);
|
||||||
|
|
||||||
|
template<Concepts::AnyString T>
|
||||||
|
ErrorOr<void> write_until_depleted(T const& buffer)
|
||||||
|
{
|
||||||
|
return write_until_depleted(StringView { buffer }.bytes());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; })
|
requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; })
|
||||||
ErrorOr<T> read_value()
|
ErrorOr<T> read_value()
|
||||||
|
|||||||
Reference in New Issue
Block a user