code_gen/rust/common/
with_unsafe_flag.rs

1use crate::CodeBuffer;
2
3/// An element with an unsafe flag.
4pub trait WithUnsafeFlag: Sized {
5    /// Gets the unsafe flag.
6    fn is_unsafe(&self) -> bool;
7
8    /// Sets the unsafe flag.
9    fn set_unsafe(&mut self);
10
11    /// Sets the unsafe flag.
12    fn with_unsafe(mut self) -> Self {
13        self.set_unsafe();
14        self
15    }
16
17    /// Writes the optional unsafe flag.
18    fn write_unsafe(&self, b: &mut CodeBuffer) {
19        if self.is_unsafe() {
20            b.write("unsafe ")
21        }
22    }
23}