code_gen/rust/common/
access.rs1use crate::{CodeBuffer, Expression};
2
3#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
5pub enum Access {
6 #[default]
7 Private,
8 Public,
9 PublicInCrate,
10 PublicInSuper,
11 PublicInPath(String),
12}
13
14impl<S: Into<String>> From<S> for Access {
15 fn from(path: S) -> Self {
16 Self::PublicInPath(path.into())
17 }
18}
19
20impl Expression for Access {
21 fn write(&self, b: &mut CodeBuffer) {
22 match self {
23 Self::Private => {}
24 Self::Public => b.write("pub "),
25 Self::PublicInCrate => b.write("pub(crate) "),
26 Self::PublicInSuper => b.write("pub(super) "),
27 Self::PublicInPath(path) => {
28 b.write("pub(in ");
29 b.write(path.as_str());
30 b.write(") ");
31 }
32 }
33 }
34}