rust_codegen/import.rs
1/// Defines an import (`use` statement).
2#[allow(dead_code)]
3#[derive(Debug, Clone)]
4pub struct Import {
5 /// The contents of the import.
6 line: String,
7 /// Import visibility.
8 pub vis: Option<String>,
9}
10
11impl Import {
12 /// Returns a new import.
13 ///
14 /// * `path` - The path to the base import.
15 /// * `ty` - The type to import.
16 ///
17 /// # Examples
18 ///
19 /// ```
20 /// use rust_codegen::Import;
21 ///
22 /// let rust_codegen_fn_import = Import::new("rust_codegen", "Function");
23 /// ```
24 pub fn new(path: &str, ty: &str) -> Self {
25 Import {
26 line: format!("{}::{}", path, ty),
27 vis: None,
28 }
29 }
30
31 /// Set the import visibility.
32 ///
33 /// # Arguments
34 ///
35 /// * `vis` - The visibility of the import.
36 ///
37 /// # Examples
38 ///
39 /// ```
40 /// use rust_codegen::Import;
41 ///
42 /// let mut rust_codegen_fn_import = Import::new("rust_codegen", "Function");
43 /// rust_codegen_fn_import.vis("pub");
44 pub fn vis(&mut self, vis: &str) -> &mut Self {
45 self.vis = Some(vis.to_string());
46 self
47 }
48}