rejectedsoftware / vibenews

Combined web forum and NNTP server implementation for stand-alone newsgroups
GNU Affero General Public License v3.0
44 stars 3 forks source link

problem with formattedWrite to OutputStream #31

Closed ghost closed 9 years ago

ghost commented 9 years ago

Here is a possible workaround for issue #30

s-ludwig commented 9 years ago

Thanks! In this case, vibe.stream.wrapper.StreamOutputRange would be the best solution here (it does't allocate, but just caches a few bytes internally for performance reasons). I'll tag a new release after a fix gets merged.

ghost commented 9 years ago

Well, I'm out of my depth. I tried

       import vibe.stream.wrapper : StreamOutputRange;
       auto dst = StreamOutputRange(res.bodyWriter);
...
            if (idx > 0) dst.write("\r\n");

            dst.formattedWrite("%d\t%s\t%s\t%s\t%s\t%s\t%d\t%d",
...
                dst.formattedWrite("\t%s: %s", h.key, sanitizeHeader(h.value));
            }
            dst.flush();

but I get a bunch of errors from std.format like this:

/usr/include/dmd/phobos/std/format.d(1953,21): Error: struct vibe.stream.wrapper.StreamOutputRange is not copyable because it is annotated with @disable
s-ludwig commented 9 years ago

Sorry, forgot about that - Since formattedWrite doesn't take the output range by reference for some reason, it needs to be called with a pointer to the range: (&dst).formattedWrite(...) (StreamOutputRange is not behaving like a reference type for efficiency reasons, in contrast to some other output ranges, such as Appender).

ghost commented 9 years ago

Now compiles and runs with StreamOutputRange. Okay? (Sorry for the extraneous white-space changes - I'm quite new to all this.)

s-ludwig commented 9 years ago

The change looks good, thanks. I'll pull and fix the formatting (as well as putting an .editorconfig file into the repository).