From f508de7bc4321db6f3dd71ea43c1cc384b7d6a7f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 19 Mar 2026 13:50:48 +0800 Subject: Refactor workspace sheet command to use structured output --- src/cmds/out/path.rs | 39 ++++++++++++++++++++++++++++ src/cmds/out/string_vcs.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 src/cmds/out/path.rs create mode 100644 src/cmds/out/string_vcs.rs (limited to 'src/cmds/out') diff --git a/src/cmds/out/path.rs b/src/cmds/out/path.rs new file mode 100644 index 0000000..2ddd643 --- /dev/null +++ b/src/cmds/out/path.rs @@ -0,0 +1,39 @@ +use serde::Serialize; +use std::path::PathBuf; + +#[derive(Serialize)] +pub struct JVPathOutput { + pub path: PathBuf, +} + +impl From for JVPathOutput { + fn from(path: PathBuf) -> Self { + JVPathOutput { path } + } +} + +impl From for PathBuf { + fn from(jv_path: JVPathOutput) -> Self { + jv_path.path + } +} + +impl AsRef for JVPathOutput { + fn as_ref(&self) -> &PathBuf { + &self.path + } +} + +impl AsRef for JVPathOutput { + fn as_ref(&self) -> &std::path::Path { + &self.path + } +} + +impl std::ops::Deref for JVPathOutput { + type Target = PathBuf; + + fn deref(&self) -> &Self::Target { + &self.path + } +} diff --git a/src/cmds/out/string_vcs.rs b/src/cmds/out/string_vcs.rs new file mode 100644 index 0000000..e01fde7 --- /dev/null +++ b/src/cmds/out/string_vcs.rs @@ -0,0 +1,65 @@ +use serde::Serialize; + +#[derive(Serialize)] +pub struct JVStringVecOutput { + pub vec: Vec, +} + +impl From> for JVStringVecOutput { + fn from(vec: Vec) -> Self { + JVStringVecOutput { vec } + } +} + +impl From for Vec { + fn from(jv_string_vec: JVStringVecOutput) -> Self { + jv_string_vec.vec + } +} + +impl AsRef> for JVStringVecOutput { + fn as_ref(&self) -> &Vec { + &self.vec + } +} + +impl AsRef<[String]> for JVStringVecOutput { + fn as_ref(&self) -> &[String] { + &self.vec + } +} + +impl std::ops::Deref for JVStringVecOutput { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.vec + } +} + +impl IntoIterator for JVStringVecOutput { + type Item = String; + type IntoIter = std::vec::IntoIter; + + fn into_iter(self) -> Self::IntoIter { + self.vec.into_iter() + } +} + +impl<'a> IntoIterator for &'a JVStringVecOutput { + type Item = &'a String; + type IntoIter = std::slice::Iter<'a, String>; + + fn into_iter(self) -> Self::IntoIter { + self.vec.iter() + } +} + +impl<'a> IntoIterator for &'a mut JVStringVecOutput { + type Item = &'a mut String; + type IntoIter = std::slice::IterMut<'a, String>; + + fn into_iter(self) -> Self::IntoIter { + self.vec.iter_mut() + } +} -- cgit