Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
megascrapper committed Mar 31, 2022
1 parent fc7f3b8 commit a307ff2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
17 changes: 12 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ impl Number {
///
/// # Panics
/// This function cannot be executed in an async runtime, as per [`reqwest::blocking`] restriction.
pub fn with_client<T: Display>(number: T, client: reqwest::blocking::Client) -> Result<Self, FactorDbError> {
pub fn with_client<T: Display>(
number: T,
client: reqwest::blocking::Client,
) -> Result<Self, FactorDbError> {
let url = format!("{}?query={}", ENDPOINT, number);
let response = client.get(url).send()?;
if response.status().is_success() {
match response.json() {
Ok(n) => Ok(n),
Err(e) => Err(e.into())
Err(e) => Err(e.into()),
}
} else {
Err(FactorDbError::InvalidNumber)
Expand Down Expand Up @@ -157,10 +160,14 @@ pub struct Factor(String, i32);

impl Factor {
/// Returns the base as a [`BigInt`].
pub fn base(&self) -> BigInt { BigInt::from_str(&self.0).unwrap() }
pub fn base(&self) -> BigInt {
BigInt::from_str(&self.0).unwrap()
}

/// Returns the exponent as a [`BigInt`].
pub fn exponent(&self) -> BigInt { BigInt::from(self.1) }
pub fn exponent(&self) -> BigInt {
BigInt::from(self.1)
}
}

impl Display for Factor {
Expand Down Expand Up @@ -208,7 +215,7 @@ pub enum FactorDbError {
RequestError(#[from] reqwest::Error),
/// Invalid number
#[error("Invalid number")]
InvalidNumber
InvalidNumber,
}

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::process::exit;
use clap::Parser;
use ansi_term::Colour::Red;
use clap::Parser;
use factordb::Number;
use std::process::exit;

/// Finds a factor to a number using FactorDB (http://factordb.com/)
#[derive(Parser, Debug)]
Expand All @@ -26,10 +26,10 @@ fn main() {
println!("{}", f);
}
}
},
}
Err(e) => {
eprintln!("{} {}", Red.paint("error:"), e);
exit(1);
}
}
}
}
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt;
use serde::{de, Deserializer};
use serde::de::Unexpected;
use serde::{de, Deserializer};
use std::fmt;

// https://stackoverflow.com/questions/37870428/convert-two-types-into-a-single-type-with-serde

Expand Down Expand Up @@ -37,4 +37,4 @@ where
D: Deserializer<'de>,
{
deserializer.deserialize_any(DeserializeIdVisitor)
}
}

0 comments on commit a307ff2

Please sign in to comment.