From e0bddbb65e36ebc2b3eb9467cad390cd6b49c912 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 3 Apr 2024 21:31:09 -0400 Subject: [PATCH] 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. --- AK/Stream.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AK/Stream.h b/AK/Stream.h index bc2db6f12d9..5fbe0bee433 100644 --- a/AK/Stream.h +++ b/AK/Stream.h @@ -7,9 +7,11 @@ #pragma once +#include #include #include #include +#include #include namespace AK { @@ -47,6 +49,12 @@ public: /// contents are written or an error occurs. virtual ErrorOr write_until_depleted(ReadonlyBytes); + template + ErrorOr write_until_depleted(T const& buffer) + { + return write_until_depleted(StringView { buffer }.bytes()); + } + template requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs>; }) ErrorOr read_value()