git_bot_feedback/output_variable.rs
1use std::fmt::Display;
2
3/// A type to represent an output variable.
4///
5/// This is akin to the key/value pairs used in most
6/// config file formats but with some limitations:
7///
8/// - Both [OutputVariable::name] and [OutputVariable::value] must be UTF-8 encoded.
9/// - The [OutputVariable::value] cannot span multiple lines.
10#[derive(Debug, Clone)]
11pub struct OutputVariable {
12 /// The output variable's name.
13 pub name: String,
14
15 /// The output variable's value.
16 pub value: String,
17}
18
19impl OutputVariable {
20 /// Validate that the output variable is well-formed.
21 ///
22 /// Typically only used by implementations of
23 /// [`RestApiClient::write_output_variables`](crate::client::RestApiClient::write_output_variables).
24 pub fn validate(&self) -> bool {
25 !self.value.contains("\n")
26 }
27}
28
29impl Display for OutputVariable {
30 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 write!(f, "{}={}", self.name, self.value)
32 }
33}