bsp_types/
bt_resources.rs

1use super::BuildTargetIdentifier;
2use serde::{Deserialize, Serialize};
3/// The build target resources request is sent from the client to the server to query for the list
4/// of resources of a given list of build targets.
5///
6/// A resource is a data dependency required to be present in the runtime classpath when a build
7/// target is run or executed. The server communicates during the initialize handshake whether this
8/// method is supported or not.
9///
10/// This request can be used by a client to highlight the resources in a project view, for example.
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
12pub struct BuildTargetResources {
13    targets: Vec<BuildTargetIdentifier>,
14}
15
16impl BuildTargetResources {
17    pub fn new(targets: Vec<BuildTargetIdentifier>) -> Self {
18        Self { targets }
19    }
20
21    /// Get a reference to the resources params's targets.
22    pub fn targets(&self) -> &[BuildTargetIdentifier] {
23        self.targets.as_ref()
24    }
25
26    /// Set the resources params's targets.
27    pub fn set_targets(&mut self, targets: Vec<BuildTargetIdentifier>) {
28        self.targets = targets;
29    }
30
31    /// Get a mutable reference to the resources params's targets.
32    pub fn targets_mut(&mut self) -> &mut Vec<BuildTargetIdentifier> {
33        &mut self.targets
34    }
35}
36
37#[derive(Default, Debug, Serialize, Deserialize, PartialEq, Eq)]
38pub struct BuildTargetResourcesResult {
39    items: Vec<Resources>,
40}
41
42impl BuildTargetResourcesResult {
43    pub fn new(items: Vec<Resources>) -> Self {
44        Self { items }
45    }
46
47    /// Get a reference to the bsp resources result's items.
48    pub fn items(&self) -> &[Resources] {
49        self.items.as_ref()
50    }
51
52    /// Get a mutable reference to the bsp resources result's items.
53    pub fn items_mut(&mut self) -> &mut Vec<Resources> {
54        &mut self.items
55    }
56}
57
58#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
59pub struct Resources {
60    target: BuildTargetIdentifier,
61    /// List of resource files.
62    resources: Vec<String>,
63}
64
65impl Resources {
66    pub fn new(target: BuildTargetIdentifier, resources: Vec<String>) -> Self {
67        Self { target, resources }
68    }
69
70    /// Set the bsp resources item's target.
71    pub fn set_target(&mut self, target: BuildTargetIdentifier) {
72        self.target = target;
73    }
74
75    /// Get a reference to the bsp resources item's target.
76    pub fn target(&self) -> &BuildTargetIdentifier {
77        &self.target
78    }
79
80    /// Set the bsp resources item's resources.
81    pub fn set_resources(&mut self, resources: Vec<String>) {
82        self.resources = resources;
83    }
84
85    /// Get a reference to the bsp resources item's resources.
86    pub fn resources(&self) -> &[String] {
87        self.resources.as_ref()
88    }
89}