IT代考 use clap::Parser;

use clap::Parser;
use unsvg::Image;

/// A simple program to parse four arguments using clap.

Copyright By PowCoder代写 加微信 powcoder

#[derive(Parser)]
struct Args {
/// Path to a file
file_path: std::path::PathBuf,

/// Path to an svg or png image
image_path: std::path::PathBuf,

/// Height
height: u32,

width: u32,

fn main() -> Result<(), ()> {
let args: Args = Args::parse();

// Access the parsed arguments
let file_path = args.file_path;
let image_path = args.image_path;
let height = args.height;
let width = args.width;

let image = Image::new(width, height);

match image_path.extension().map(|s| s.to_str()).flatten() {
Some(“svg”) => {
let res = image.save_svg(&image_path);
if let Err(e) = res {
eprintln!(“Error saving svg: {e}”);
return Err(());
Some(“png”) => {
let res = image.save_png(&image_path);
if let Err(e) = res {
eprintln!(“Error saving png: {e}”);
return Err(());
eprintln!(“File extension not supported”);
return Err(());

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com