Is it undefined behavior to do runtime borrow management with the help of raw pointers in Rust?
问题 As part of binding a C API to Rust, I have a mutable reference ph: &mut Ph , a struct struct EnsureValidContext<'a> { ph: &'a mut Ph } , and some methods: impl Ph { pub fn print(&mut self, s: &str) { /*...*/ } pub fn with_context<F, R>(&mut self, ctx: &Context, f: F) -> Result<R, InvalidContextError> where F: Fn(EnsureValidContext) -> R, { /*...*/ } /* some others */ } impl<'a> EnsureValidContext<'a> { pub fn print(&mut self, s: &str) { self.ph.print(s) } pub fn close(self) {} /* some others