-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1763 from fermyon/update-wasmtime13
Update to wasmtime 13
- Loading branch information
Showing
15 changed files
with
1,039 additions
and
661 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,33 @@ | ||
use std::sync::{Arc, RwLock}; | ||
|
||
use wasmtime_wasi::preview2::pipe::WritePipe; | ||
use wasmtime_wasi::preview2::{pipe::MemoryOutputPipe, HostOutputStream}; | ||
|
||
/// An in-memory stdio output buffer. | ||
#[derive(Default)] | ||
pub struct OutputBuffer(Arc<RwLock<Vec<u8>>>); | ||
pub struct OutputBuffer(MemoryOutputPipe); | ||
|
||
impl OutputBuffer { | ||
/// Takes the buffered output from this buffer. | ||
pub fn take(&mut self) -> Vec<u8> { | ||
std::mem::take(&mut *self.0.write().unwrap()) | ||
/// Clones the buffered output from this buffer. | ||
pub fn contents(&self) -> bytes::Bytes { | ||
self.0.contents() | ||
} | ||
|
||
pub(crate) fn writer(&self) -> WritePipe<Vec<u8>> { | ||
WritePipe::from_shared(self.0.clone()) | ||
pub(crate) fn writer(&self) -> impl HostOutputStream { | ||
self.0.clone() | ||
} | ||
} | ||
|
||
impl Default for OutputBuffer { | ||
fn default() -> Self { | ||
Self(MemoryOutputPipe::new(usize::MAX)) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use wasmtime_wasi::preview2::OutputStream; | ||
|
||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn take_what_you_write() { | ||
let mut buf = OutputBuffer::default(); | ||
buf.writer().write(b"foo").await.unwrap(); | ||
assert_eq!(buf.take(), b"foo"); | ||
let buf = OutputBuffer::default(); | ||
buf.writer().write(b"foo".to_vec().into()).unwrap(); | ||
assert_eq!(buf.contents().as_ref(), b"foo"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.