tf_bindgen/codegen/
path.rs

1use heck::ToUpperCamelCase;
2
3/// Used to manage Terraform id's and construct paths.
4#[derive(Clone, Debug)]
5pub struct Path {
6    segments: Vec<String>,
7}
8
9impl Path {
10    pub fn empty() -> Self {
11        Self {
12            segments: Vec::new(),
13        }
14    }
15
16    pub fn new(segments: Vec<String>) -> Self {
17        Self { segments }
18    }
19
20    /// Concatenate path segments as camel case to type.
21    pub fn type_name(&self) -> String {
22        self.segments
23            .iter()
24            .map(|seg| seg.to_upper_camel_case())
25            .collect()
26    }
27
28    /// Concatenate path segments as camel case to type. Will ignore the first segments.
29    pub fn type_name_reduced(&self) -> String {
30        self.segments
31            .iter()
32            .skip(1)
33            .map(|seg| seg.to_upper_camel_case())
34            .collect()
35    }
36
37    pub fn segments(&self) -> impl Iterator<Item = &String> {
38        self.segments.iter()
39    }
40
41    pub fn push(&mut self, path: impl Into<String>) {
42        self.segments.push(path.into())
43    }
44}