Skip to content

Commit b7105bd

Browse files
feat(evm): add AsEnvMut::set_env (foundry-rs#13573)
1 parent c0fe76c commit b7105bd

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

crates/evm/core/src/env.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ impl EnvMut<'_> {
4848
tx: self.tx.to_owned(),
4949
}
5050
}
51+
52+
/// Writes an owned [`Env`] back into the context.
53+
///
54+
/// Counterpart to [`to_owned`](Self::to_owned): completes the read/write pair so callers
55+
/// that receive an updated [`Env`] by value (e.g. after a fork switch or snapshot revert)
56+
/// can apply it without manually assigning each field.
57+
pub fn set_env(&mut self, env: Env) {
58+
*self.block = env.evm_env.block_env;
59+
*self.cfg = env.evm_env.cfg_env;
60+
*self.tx = env.tx;
61+
}
5162
}
5263

5364
pub trait AsEnvMut {

0 commit comments

Comments
 (0)