brendandburns opened PR #6228 from brendandburns:ptr
to bytecodealliance:main
:
This is related to the discussion here: https://github.com/WebAssembly/wasi-http/issues/24
Where we decided that streams should be
child-own
properties of the request or response that they are tied to.This adds clarity to when it is valid to drop an input or output stream and in what order relative to the response.
brendandburns requested alexcrichton for a review on PR #6228.
brendandburns requested wasmtime-core-reviewers for a review on PR #6228.
alexcrichton requested pchickey for a review on PR #6228.
rvolosatovs submitted PR review.
rvolosatovs submitted PR review.
rvolosatovs created PR review comment:
Doesn't
with_context
work here?
rvolosatovs created PR review comment:
nit; since we only care about the
Some
case, how about anif let Some(r) = self.requests.get(&request)
instead?Or even
if let Entry::Occupied(e) = self.requests.entry(request) { let r = e.remove();
https://doc.rust-lang.org/std/collections/hash_map/struct.OccupiedEntry.html#method.remove
rvolosatovs created PR review comment:
If we had a
Default
trait impl, this could have just calledSelf::default()
rvolosatovs created PR review comment:
How about a
derive(Default)
?
rvolosatovs created PR review comment:
You wouldn't need this clone if the call to
buf.len
below was moved higher, before the match.
rvolosatovs created PR review comment:
If we had
Default
implemented, this could have beenunwrap_or_default
rvolosatovs created PR review comment:
Looking at the usages of this struct, it seems that a
From<Bytes>
implementation could really clear this up
rvolosatovs created PR review comment:
If there was a
From
implementation, this could have beenStream::from(new.freeze())
brendandburns created PR review comment:
Unfortunately,
HashMap::get(...)
returns a reference rather than a value, and there's no default for a reference. I could implement theDefault
trait for&Stream
references, but I'm not sure if that's what is best. Let me know.
brendandburns created PR review comment:
done.
brendandburns created PR review comment:
done.
brendandburns created PR review comment:
I'm not sure I'm following your suggestion, can you clarify?
brendandburns created PR review comment:
done.
brendandburns created PR review comment:
added.
brendandburns created PR review comment:
done.
brendandburns created PR review comment:
Done.
Thanks for the suggestion, I'm still learning idiomatic rust)
brendandburns updated PR #6228.
brendandburns updated PR #6228.
rvolosatovs created PR review comment:
Sure, I'm referring to this method on the
anyhow::Context
trait https://docs.rs/anyhow/latest/anyhow/trait.Context.html#tymethod.with_contextIf it's in scope, you should be able to call
context
orwith_context
(usually used withformat!
and similar) on mostResult
and allOption
types directly, thus eliminating the need forok_or_else
and explicitanyhow!
invocation
rvolosatovs created PR review comment:
That makes sense, I think this is fine.
I am making a few changes here to allow for the host to provide a custom connect implementation, so I'll take a deeper look at this as well next week
rvolosatovs submitted PR review:
Just a general question, why are we not modifying the stream data buffer, but rather cloning it? In other words, why would we ever want to read the same bytes more than once?
rvolosatovs submitted PR review:
Just a general question, why are we not modifying the stream data buffer, but rather cloning it? In other words, why would we ever want to read the same bytes more than once?
rvolosatovs created PR review comment:
This should probably also use the
From
trait
brendandburns created PR review comment:
done.
pchickey created PR review comment:
I made those ok_or_else(|| anyhow!(...)) suggestions in a prior PR and wasn't aware that Context could do that for me. Thank you.
@brendandburns The suggested change here is
let st = self.streams.get_mut(&stream).with_context(|| format!("stream not found: {stream}"))?;
, or maybe even....get_mut(&stream).context("stream not found")?
if leaving out the stream number is ok - and it probably is, because (at least when using the component linker, I'm not sure if it works in module mode) bindgen is insertingtracing
statements which someone debugging can recover the values of the arguments from.
pchickey edited PR review comment.
pchickey submitted PR review.
pchickey submitted PR review.
pchickey created PR review comment:
bail!("cannot write to closed stream");
rvolosatovs submitted PR review.
rvolosatovs submitted PR review.
rvolosatovs created PR review comment:
From https://github.com/bytecodealliance/wasmtime/pull/6228#issuecomment-1516661764, as you said, I think I'd just use
BytesMut
and https://docs.rs/bytes/latest/bytes/struct.BytesMut.html#method.extend_from_slice hereThis that would be quite a bit shorter, it could probably also make sense to remove the match altogether and instead rely on https://doc.rust-lang.org/std/collections/hash_map/enum.Entry.html#method.and_modify (see example there with
or_insert
)
rvolosatovs edited PR review comment.
brendandburns updated PR #6228.
brendandburns updated PR #6228.
brendandburns created PR review comment:
Done. I needed to use
.or_default().extend_from_slice(...)
but I think it achieves the same goal (and thanks for the suggestion of implementingDefault
that made it possible :)
pchickey merged PR #6228.
rvolosatovs created PR review comment:
Last updated: Nov 22 2024 at 16:03 UTC