Skip to main content

miden_project/ast/
target.rs

1use crate::{ast::parsing::SetSourceId, *};
2
3#[derive(Debug, Clone)]
4#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
6pub struct LibTarget {
7    /// The kind of library target this is.
8    ///
9    /// Defaults to `library`
10    #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
11    pub kind: Option<Span<TargetType>>,
12    /// The optional namespace override for modules parsed from this target
13    #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
14    pub namespace: Option<Span<Arc<str>>>,
15    /// The relative path from the project manifest to the root source file for this target
16    #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
17    pub path: Option<Span<Uri>>,
18}
19
20#[derive(Debug, Clone)]
21#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
22#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
23pub struct BinTarget {
24    /// An optional name for this target.
25    ///
26    /// If unspecified, the name defaults to `$exec`.
27    ///
28    /// All binary target names must be unique in a project.
29    #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
30    pub name: Option<Span<Arc<str>>>,
31    /// The relative path from the project manifest to the root source file for this target
32    #[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
33    pub path: Option<Span<Uri>>,
34}
35
36impl SetSourceId for LibTarget {
37    fn set_source_id(&mut self, source_id: SourceId) {
38        if let Some(kind) = self.kind.as_mut() {
39            kind.set_source_id(source_id);
40        }
41
42        if let Some(ns) = self.namespace.as_mut() {
43            ns.set_source_id(source_id);
44        }
45
46        if let Some(path) = self.path.as_mut() {
47            path.set_source_id(source_id);
48        }
49    }
50}
51
52impl SetSourceId for BinTarget {
53    fn set_source_id(&mut self, source_id: SourceId) {
54        if let Some(ns) = self.name.as_mut() {
55            ns.set_source_id(source_id);
56        }
57
58        if let Some(path) = self.path.as_mut() {
59            path.set_source_id(source_id);
60        }
61    }
62}