summaryrefslogtreecommitdiffstats
path: root/src/builder.rs
diff options
context:
space:
mode:
authorWojciech Kępka <46892771+wojciechkepka@users.noreply.github.com>2021-02-06 07:57:49 +0100
committerGitHub <noreply@github.com>2021-02-06 01:57:49 -0500
commitef3dfad8f691f64e41fb1d369399471cde6ad8c0 (patch)
treee8b5bba9d148b3522171eaf72b33624334774416 /src/builder.rs
parent9b85dc8a9d370139e8eb3cafadf5a0f8f6dc6597 (diff)
Add Exec struct for easier manipulation of exec instances (#251)
* Add ExecDetails and ProcessConfig * Add exec_with_id, exec_inspect * Add example how to inspect an exec instance * Make clippy happy * exit_code is an Option on ExecDetails * Add Exec struct * Update example * Fix typo * Add Exec::resize and ExecResizeOptions * Add resize example
Diffstat (limited to 'src/builder.rs')
-rw-r--r--src/builder.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/builder.rs b/src/builder.rs
index 110abcc..6971be9 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -1701,6 +1701,75 @@ impl VolumeCreateOptionsBuilder {
}
}
}
+///
+/// Interface for creating volumes
+#[derive(Serialize, Debug)]
+pub struct ExecResizeOptions {
+ params: HashMap<&'static str, Value>,
+}
+
+impl ExecResizeOptions {
+ /// serialize options as a string. returns None if no options are defined
+ pub fn serialize(&self) -> Result<String> {
+ serde_json::to_string(&self.params).map_err(Error::from)
+ }
+
+ pub fn parse_from<'a, K, V>(
+ &self,
+ params: &'a HashMap<K, V>,
+ body: &mut BTreeMap<String, Value>,
+ ) where
+ &'a HashMap<K, V>: IntoIterator,
+ K: ToString + Eq + Hash,
+ V: Serialize,
+ {
+ for (k, v) in params.iter() {
+ let key = k.to_string();
+ let value = serde_json::to_value(v).unwrap();
+
+ body.insert(key, value);
+ }
+ }
+
+ /// return a new instance of a builder for options
+ pub fn builder() -> ExecResizeOptionsBuilder {
+ ExecResizeOptionsBuilder::new()
+ }
+}
+
+#[derive(Default)]
+pub struct ExecResizeOptionsBuilder {
+ params: HashMap<&'static str, Value>,
+}
+
+impl ExecResizeOptionsBuilder {
+ pub(crate) fn new() -> Self {
+ let params = HashMap::new();
+ ExecResizeOptionsBuilder { params }
+ }
+
+ pub fn height(
+ &mut self,
+ height: u64,
+ ) -> &mut Self {
+ self.params.insert("Name", json!(height));
+ self
+ }
+
+ pub fn width(
+ &mut self,
+ width: u64,
+ ) -> &mut Self {
+ self.params.insert("Name", json!(width));
+ self
+ }
+
+ pub fn build(&self) -> ExecResizeOptions {
+ ExecResizeOptions {
+ params: self.params.clone(),
+ }
+ }
+}
#[cfg(test)]
mod tests {