Put context object behind a ref rather than mut ref

This commit puts context object, i.e., the implementor of the
WASI snapshot, behind a reference `&self` rather than a mutable
reference `&mut self`. As suggested by @alexcrichton, this gives
the implementor the possibility to determine how it handles its
interior mutability.
This commit is contained in:
Jakub Konka
2020-03-03 15:25:11 +01:00
committed by Jakub Konka
parent ea4d2d0535
commit 3764204250
13 changed files with 74 additions and 78 deletions

View File

@@ -32,7 +32,7 @@ fn mult_zero_nan(a: f32, b: u32) -> f32 {
}
impl union_example::UnionExample for WasiCtx {
fn get_tag(&mut self, u: &types::Reason) -> Result<types::Excuse, types::Errno> {
fn get_tag(&self, u: &types::Reason) -> Result<types::Excuse, types::Errno> {
println!("GET TAG: {:?}", u);
match u {
types::Reason::DogAte { .. } => Ok(types::Excuse::DogAte),
@@ -40,11 +40,7 @@ impl union_example::UnionExample for WasiCtx {
types::Reason::Sleeping { .. } => Ok(types::Excuse::Sleeping),
}
}
fn reason_mult(
&mut self,
u: &types::ReasonMut<'_>,
multiply_by: u32,
) -> Result<(), types::Errno> {
fn reason_mult(&self, u: &types::ReasonMut<'_>, multiply_by: u32) -> Result<(), types::Errno> {
match u {
types::ReasonMut::DogAte(fptr) => {
let mut f = fptr.as_ref_mut().expect("valid pointer");