From 2e035be60a2f6067cc7b170e1e269f483bb5ec7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Gaspard?= Date: Wed, 13 Jan 2021 04:51:00 +0100 Subject: [PATCH] make WasiCtxBuilder be an actual builder, allowing to call .build() at the end of a call chain --- crates/wasi-c2/src/ctx.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/wasi-c2/src/ctx.rs b/crates/wasi-c2/src/ctx.rs index b9e74e3c18..5f60ccca9c 100644 --- a/crates/wasi-c2/src/ctx.rs +++ b/crates/wasi-c2/src/ctx.rs @@ -66,12 +66,12 @@ impl WasiCtxBuilder { Ok(self.0) } - pub fn arg(&mut self, arg: &str) -> Result<&mut Self, StringArrayError> { + pub fn arg(mut self, arg: &str) -> Result { self.0.args.push(arg.to_owned())?; Ok(self) } - pub fn stdin(&mut self, f: Box) -> &mut Self { + pub fn stdin(mut self, f: Box) -> Self { self.0.insert_file( 0, f, @@ -80,7 +80,7 @@ impl WasiCtxBuilder { self } - pub fn stdout(&mut self, f: Box) -> &mut Self { + pub fn stdout(mut self, f: Box) -> Self { self.0.insert_file( 1, f, @@ -89,7 +89,7 @@ impl WasiCtxBuilder { self } - pub fn stderr(&mut self, f: Box) -> &mut Self { + pub fn stderr(mut self, f: Box) -> Self { self.0.insert_file( 2, f, @@ -98,17 +98,17 @@ impl WasiCtxBuilder { self } - pub fn inherit_stdio(&mut self) -> &mut Self { + pub fn inherit_stdio(self) -> Self { self.stdin(Box::new(crate::stdio::stdin())) .stdout(Box::new(crate::stdio::stdout())) .stderr(Box::new(crate::stdio::stderr())) } pub fn preopened_dir( - &mut self, + mut self, dir: Box, path: impl AsRef, - ) -> Result<&mut Self, Error> { + ) -> Result { let caps = DirCaps::all(); let file_caps = FileCaps::all(); self.0.table().push(Box::new(DirEntry::new( @@ -120,7 +120,7 @@ impl WasiCtxBuilder { Ok(self) } - pub fn random(&mut self, random: Box) -> &mut Self { + pub fn random(mut self, random: Box) -> Self { self.0.random.replace(random); self }