How to code repeated structs and comments? #5835
-
const FILE_DOC: &str = "Accepts a valid .png file.";
const CHUNK_DOC: &str = "Accepts an exact 4byte ASCII(alphabetic only) sequence. eg: [rust, bOAT].";
#[derive(Subcommand)]
pub enum Commands {
/// Encode data in a png.
/// `chunk_type` double as label to refer the hidden data.
Encode {
file: PathBuf,
chunk_type: ChunkType,
/// The data you want to hide.
message: String,
/// Optionally a output path to store the new encoded png.
output_file: Option<PathBuf>,
},
/// Encode data in a png.
/// use `chunk_type` to refer to the hidden message.
Decode {
file: PathBuf,
chunk_type: ChunkType,
},
/// Remove a chunk from a png.
/// Must provide the `chunk_type` which act as label.
Remove {
file: PathBuf,
chunk_type: ChunkType,
},
/// Displays PNG in bytes form.
Print { file: PathBuf },
} I have these subcommands in my cli, each have a very similar struct (Decode and Remove have exact same) fields are also overlapping, how can i avoid adding same piece of documentation as seen in |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I would be cautious about sharing too much code because its very easy to see the similarities today but things can evolve (e.g. specializing documentation for the context) and the burden to unwind all of that can lead to other hacky behavior. We've been hitting that recently in Cargo with some of the argument sharing we do there (though that uses the builder API). If you still want to go forward, you can derive |
Beta Was this translation helpful? Give feedback.
Oh, yes, you could do
#[arg(about = FILE_DOC)]