implement randomness

This commit is contained in:
Pat Hickey
2021-01-04 12:20:42 -08:00
parent 01d74ceb73
commit 48554a1a5c
5 changed files with 50 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
use crate::dir::{DirCaps, DirEntry, WasiDir};
use crate::file::{FileCaps, FileEntry, WasiFile};
use crate::random::WasiRandom;
use crate::string_array::{StringArray, StringArrayError};
use crate::table::Table;
use crate::Error;
@@ -10,6 +11,7 @@ use std::rc::Rc;
pub struct WasiCtx {
pub(crate) args: StringArray,
pub(crate) env: StringArray,
pub(crate) random: Box<dyn WasiRandom>,
table: Rc<RefCell<Table>>,
}
@@ -22,6 +24,7 @@ impl WasiCtx {
WasiCtx {
args: StringArray::new(),
env: StringArray::new(),
random: Box::new(crate::random::GetRandom),
table: Rc::new(RefCell::new(Table::new())),
}
}
@@ -110,4 +113,9 @@ impl WasiCtxBuilder {
)))?;
Ok(self)
}
pub fn random(&mut self, random: Box<dyn WasiRandom>) -> &mut Self {
self.0.random = random;
self
}
}