bsp_types/
bt_clean_cache.rs

1use serde::{Deserialize, Serialize};
2
3use super::BuildTargetIdentifier;
4
5/// The clean cache request is sent from the client to the server to reset any state associated with
6/// a given build target. The state can live either in the build tool or in the file system.
7///
8/// The build tool defines the exact semantics of the clean cache request:
9///
10/// Stateless build tools are free to ignore the request and respond with a successful response.
11/// Stateful build tools must ensure that invoking compilation on a target that has been cleaned
12/// results in a full compilation.
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14pub struct BuildTargetCleanCache {
15    /// The build targets to clean.
16    targets: Vec<BuildTargetIdentifier>,
17}
18
19impl BuildTargetCleanCache {
20    /// Get a reference to the bsp btclean cache params's targets.
21    pub fn targets(&self) -> &[BuildTargetIdentifier] {
22        self.targets.as_ref()
23    }
24
25    /// Get a mutable reference to the bsp btclean cache params's targets.
26    pub fn targets_mut(&mut self) -> &mut Vec<BuildTargetIdentifier> {
27        &mut self.targets
28    }
29
30    pub fn is_empty(&self) -> bool {
31        self.targets.is_empty()
32    }
33
34    /// Set the bsp btclean cache params's targets.
35    pub fn set_targets(&mut self, targets: Vec<BuildTargetIdentifier>) {
36        self.targets = targets;
37    }
38}
39
40#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
41pub struct BuildTargetCleanCacheResult {
42    /// Optional message to display to the user.
43    #[serde(skip_serializing_if = "Option::is_none")]
44    message: Option<String>,
45    /// Indicates whether the clean cache request was performed or not.
46    cleaned: bool,
47}
48
49impl BuildTargetCleanCacheResult {
50    pub fn new(message: Option<String>, cleaned: bool) -> Self {
51        Self { message, cleaned }
52    }
53    pub fn new_simple(cleaned: bool) -> Self {
54        Self {
55            message: None,
56            cleaned,
57        }
58    }
59
60    /// Get a reference to the clean cache result's message.
61    pub fn message(&self) -> Option<&String> {
62        self.message.as_ref()
63    }
64
65    /// Get the clean cache result's cleaned.
66    pub fn cleaned(&self) -> bool {
67        self.cleaned
68    }
69
70    /// Set the clean cache result's cleaned.
71    pub fn set_cleaned(&mut self, cleaned: bool) {
72        self.cleaned = cleaned;
73    }
74
75    /// Set the clean cache result's message.
76    pub fn set_message(&mut self, message: Option<String>) {
77        self.message = message;
78    }
79}