From a3b5806c3e6f8907cffa21f3b14952da606895db Mon Sep 17 00:00:00 2001 From: Preyas Shah Date: Mon, 22 Jul 2024 10:41:17 -0700 Subject: [PATCH 1/2] skip deserialization, just use a &str --- martian/src/stage.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/martian/src/stage.rs b/martian/src/stage.rs index 3ecd835662..69c3c2dba0 100644 --- a/martian/src/stage.rs +++ b/martian/src/stage.rs @@ -125,8 +125,12 @@ pub struct Resource { threads: Option, #[serde(rename = "__vmem_gb", skip_serializing_if = "Option::is_none")] vmem_gb: Option, - #[serde(rename = "__special", skip_serializing_if = "Option::is_none")] - special: Option, + #[serde( + rename = "__special", + skip_serializing_if = "Option::is_none", + skip_deserializing + )] + special: Option<&'static str>, } impl Resource { @@ -167,8 +171,8 @@ impl Resource { } /// Get the special resource request - pub fn get_special(&self) -> Option { - self.special.clone() + pub fn get_special(&self) -> Option<&'static str> { + self.special } /// Set the mem_gb @@ -217,13 +221,13 @@ impl Resource { /// ```rust /// use martian::Resource; /// - /// let resource = Resource::new().mem_gb(2).vmem_gb(4).special("gpu_count1_mem8".to_owned()); + /// let resource = Resource::new().mem_gb(2).vmem_gb(4).special("gpu_count1_mem8"); /// assert_eq!(resource.get_mem_gb(), Some(2)); /// assert_eq!(resource.get_vmem_gb(), Some(4)); /// assert_eq!(resource.get_threads(), None); - /// assert_eq!(resource.get_special(), Some("gpu_count1_mem8".to_owned())); + /// assert_eq!(resource.get_special(), Some("gpu_count1_mem8")); /// ``` - pub fn special(mut self, special: String) -> Self { + pub fn special(mut self, special: &'static str) -> Self { self.special = Some(special); self } From 327f82a05287c772d9ab688a095583f8decc8ad2 Mon Sep 17 00:00:00 2001 From: Preyas Shah Date: Mon, 22 Jul 2024 10:58:50 -0700 Subject: [PATCH 2/2] do Copy again --- martian-lab/examples/sum_sq/src/sum_squares.rs | 2 +- martian/src/stage.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/martian-lab/examples/sum_sq/src/sum_squares.rs b/martian-lab/examples/sum_sq/src/sum_squares.rs index 5a046c9404..4076ebb611 100644 --- a/martian-lab/examples/sum_sq/src/sum_squares.rs +++ b/martian-lab/examples/sum_sq/src/sum_squares.rs @@ -71,7 +71,7 @@ impl MartianStage for SumSquares { for value in args.values { let chunk_inputs = SumSquaresChunkInputs { value }; // It is optional to create a chunk with resource. If not specified, default resource will be used - stage_def.add_chunk_with_resource(chunk_inputs, chunk_resource.clone()); + stage_def.add_chunk_with_resource(chunk_inputs, chunk_resource); } // Return the stage definition Ok(stage_def) diff --git a/martian/src/stage.rs b/martian/src/stage.rs index 69c3c2dba0..49682a22be 100644 --- a/martian/src/stage.rs +++ b/martian/src/stage.rs @@ -117,7 +117,7 @@ impl MartianMakePath for T { /// /// Memory/ thread request can be negative in matrian. See /// [http://martian-lang.org/advanced-features/#resource-consumption](http://martian-lang.org/advanced-features/#resource-consumption) -#[derive(Debug, Serialize, Deserialize, Clone, Default)] +#[derive(Debug, Serialize, Deserialize, Copy, Clone, Default)] pub struct Resource { #[serde(rename = "__mem_gb", skip_serializing_if = "Option::is_none")] mem_gb: Option, @@ -637,7 +637,7 @@ pub trait MartianStage: MroMaker { fill_defaults(resource), )) } - let rover = _chunk_prelude(chunk_idx, run_directory, chunk.resource.clone())?; + let rover = _chunk_prelude(chunk_idx, run_directory, chunk.resource)?; self.main(args.clone(), chunk.inputs.clone(), rover) };