src: add mod files
This commit is contained in:
parent
296b77eb25
commit
d1ce228c35
3 changed files with 25 additions and 24 deletions
12
src/args.rs
Normal file
12
src/args.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
pub struct Args {
|
||||
pub app_id: String,
|
||||
#[arg(short, long)]
|
||||
pub from: String,
|
||||
#[arg(short, long)]
|
||||
pub to: String,
|
||||
#[arg(short, long)]
|
||||
pub value: String,
|
||||
}
|
28
src/main.rs
28
src/main.rs
|
@ -1,32 +1,12 @@
|
|||
use clap::Parser;
|
||||
use reqwest::Error;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
||||
pub struct Args {
|
||||
#[arg(short, long)]
|
||||
app_id: String,
|
||||
#[arg(short, long)]
|
||||
from: String,
|
||||
#[arg(short, long)]
|
||||
to: String,
|
||||
#[arg(short, long)]
|
||||
value: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Payload {
|
||||
base_code: String,
|
||||
target_code: String,
|
||||
conversion_rate: f64,
|
||||
conversion_result: f64,
|
||||
}
|
||||
mod args;
|
||||
mod payload;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Error> {
|
||||
let args = Args::parse();
|
||||
let args = args::Args::parse();
|
||||
let url = format!(
|
||||
"https://v6.exchangerate-api.com/v6/{}/pair/{}/{}/{}",
|
||||
args.app_id, args.from, args.to, args.value
|
||||
|
@ -37,7 +17,7 @@ async fn main() -> Result<(), Error> {
|
|||
match client.get(url).send().await {
|
||||
Ok(response) => {
|
||||
if response.status().is_success() {
|
||||
match response.json::<Payload>().await {
|
||||
match response.json::<payload::Payload>().await {
|
||||
Ok(payload) => {
|
||||
println!("From: {:?}", payload.base_code);
|
||||
println!("To: {:?}", payload.target_code);
|
||||
|
|
9
src/payload.rs
Normal file
9
src/payload.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Payload {
|
||||
pub base_code: String,
|
||||
pub target_code: String,
|
||||
pub conversion_rate: f64,
|
||||
pub conversion_result: f64,
|
||||
}
|
Loading…
Reference in a new issue