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:
Timothy Flynn 2024-04-03 21:31:09 -04:00 committed by Andreas Kling
parent c7ea710b55
commit e0bddbb65e

View file

@ -7,9 +7,11 @@
#pragma once
#include <AK/Concepts.h>
#include <AK/Error.h>
#include <AK/Format.h>
#include <AK/Forward.h>
#include <AK/StringView.h>
#include <AK/Traits.h>
namespace AK {
@ -47,6 +49,12 @@ public:
/// contents are written or an error occurs.
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>
requires(requires(Stream& stream) { { T::read_from_stream(stream) } -> SameAs<ErrorOr<T>>; })
ErrorOr<T> read_value()