cxx_build/gen/
block.rs

1use proc_macro2::Ident;
2
3#[derive(#[automatically_derived]
impl<'a> ::core::marker::Copy for Block<'a> { }Copy, #[automatically_derived]
impl<'a> ::core::clone::Clone for Block<'a> {
    #[inline]
    fn clone(&self) -> Block<'a> {
        let _: ::core::clone::AssertParamIsClone<&'a str>;
        let _: ::core::clone::AssertParamIsClone<&'a Ident>;
        let _: ::core::clone::AssertParamIsClone<&'a str>;
        *self
    }
}Clone, #[automatically_derived]
impl<'a> ::core::cmp::PartialEq for Block<'a> {
    #[inline]
    fn eq(&self, other: &Block<'a>) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (Block::Namespace(__self_0), Block::Namespace(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Block::UserDefinedNamespace(__self_0),
                    Block::UserDefinedNamespace(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (Block::InlineNamespace(__self_0),
                    Block::InlineNamespace(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl<'a> ::core::fmt::Debug for Block<'a> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Block::AnonymousNamespace =>
                ::core::fmt::Formatter::write_str(f, "AnonymousNamespace"),
            Block::Namespace(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Namespace", &__self_0),
            Block::UserDefinedNamespace(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "UserDefinedNamespace", &__self_0),
            Block::InlineNamespace(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "InlineNamespace", &__self_0),
            Block::ExternC => ::core::fmt::Formatter::write_str(f, "ExternC"),
        }
    }
}Debug)]
4pub(crate) enum Block<'a> {
5    AnonymousNamespace,
6    Namespace(&'a str),
7    UserDefinedNamespace(&'a Ident),
8    InlineNamespace(&'a str),
9    ExternC,
10}
11
12impl<'a> Block<'a> {
13    pub(crate) fn write_begin(self, out: &mut String) {
14        if let Block::InlineNamespace(_) = self {
15            out.push_str("inline ");
16        }
17        self.write_common(out);
18        out.push_str(" {\n");
19    }
20
21    pub(crate) fn write_end(self, out: &mut String) {
22        out.push_str("} // ");
23        self.write_common(out);
24        out.push('\n');
25    }
26
27    fn write_common(self, out: &mut String) {
28        match self {
29            Block::AnonymousNamespace => out.push_str("namespace"),
30            Block::Namespace(name) => {
31                out.push_str("namespace ");
32                out.push_str(name);
33            }
34            Block::UserDefinedNamespace(name) => {
35                out.push_str("namespace ");
36                out.push_str(&name.to_string());
37            }
38            Block::InlineNamespace(name) => {
39                out.push_str("namespace ");
40                out.push_str(name);
41            }
42            Block::ExternC => out.push_str("extern \"C\""),
43        }
44    }
45}