MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / with

Method with

14_context_manager/rust/context_manager.rs:19–29  ·  view source on GitHub ↗
(self: &mut Self, f: F)

Source from the content-addressed store, hash-verified

17 }
18
19 fn with<F>(self: &mut Self, f: F) -> io::Result<()>
20 where
21 F: Fn(&mut File) -> io::Result<()>,
22 {
23 if self.mode == 'w' {
24 self.file = Some(File::create(&self.filename)?);
25 f(&mut self.file.as_mut().unwrap())?;
26 self.file = None;
27 }
28 Ok(())
29 }
30
31 fn closed(self: &Self) -> bool {
32 self.file.is_none()

Callers 1

mainFunction · 0.80

Calls 1

fFunction · 0.85

Tested by

no test coverage detected