-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.fmt.format — with streams #4628
Conversation
454fece
to
9b8ae23
Compare
I think this can be a major problem when doing user interfaces. I use |
@MasterQ32 I think the new OutStream rewrite solves the always-async problem, and it exposes that the concept of an OutStream is just |
@@ -155,7 +151,7 @@ pub const Buffer = struct { | |||
} | |||
|
|||
pub fn print(self: *Buffer, comptime fmt: []const u8, args: var) !void { | |||
return std.fmt.format(self, error{OutOfMemory}, Buffer.append, fmt, args); | |||
return self.outStream().print(fmt, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that the stream is readily available, maybe this method should be deleted.
This idea is approved ✔️ but I haven't reviewed the PR yet |
Spiritual successor to #4059. Thanks to @daurnimator for suggesting this approach.
Like generators, we can coalesce context/output/error into one argument.
Unlike generators, we don't have to invent a new pattern. OutStream is already an existing standard, and we just have to leverage its functionality. This also circumvents the previously encountered generator footguns since we have at most 1 async context.
The major downside is that OutStream is currently "all or nothing" when it comes to async, which would prevent non-async version of format(). Not sure how much of a problem this is and it's not specific to justformat()
, and this could be solvable by introducing noasync OutStreams (yay colors?)solved via #4710