mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +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:
parent
c7ea710b55
commit
e0bddbb65e
Notes:
sideshowbarker
2024-07-17 03:25:24 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/e0bddbb65e Pull-request: https://github.com/SerenityOS/serenity/pull/23830 Reviewed-by: https://github.com/shannonbooth ✅
1 changed files with 8 additions and 0 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue