Skip to content

Commit

Permalink
Merge pull request #9 from JeromeSchmied/clippy
Browse files Browse the repository at this point in the history
code quality
  • Loading branch information
luleyleo authored Sep 3, 2024
2 parents dabf611 + dd73da6 commit 4f49fc4
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 31 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ edition = "2021"

[dependencies]
chrono = "0.4"
reqwest = {version = "0.11", features= ["cookies", "json", "blocking"]}
serde = "1.0"
serde_derive = "1.0"
reqwest = { version = "0.11", features = ["cookies", "json", "blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
3 changes: 0 additions & 3 deletions examples/get_timetable.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use chrono;
use untis;

///
/// This example shows a basic usecase of searching for a specific school
/// and then retrieving a user's own timetable.
Expand Down
2 changes: 0 additions & 2 deletions examples/search_for_school.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use untis;

///
/// This example shows a basic usecase of searching for schools.
///
Expand Down
6 changes: 2 additions & 4 deletions examples/view_timetables.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use untis;

///
/// This example shows how you can access a list of your school's teachers and how
/// you can view the timetables of other people/assets (i.e. rooms). Note that your
Expand Down Expand Up @@ -30,8 +28,8 @@ fn main() -> Result<(), untis::Error> {
println!(
"{}, {}-{}",
weekday(lesson.date),
lesson.start_time.to_string(),
lesson.end_time.to_string()
*lesson.start_time,
*lesson.end_time
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Client {
let params = params::AuthenticateParams {
client: "untis-rs",
user: username,
password: password,
password,
};
let mut rpc_client = jsonrpc::Client::new(&make_untis_url(server, school));
let session: Session = rpc_client.request("authenticate", params)?;
Expand Down
4 changes: 2 additions & 2 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ impl<'de> Deserialize<'de> for Date {

fn chrono_to_untis_date(date: NaiveDate) -> u32 {
let string = format!("{}", date.format("%Y%m%d"));
let number = string.parse::<u32>().unwrap();
number
string.parse::<u32>().unwrap()
}

fn chrono_from_untis_date(value: u32) -> NaiveDate {
Expand Down Expand Up @@ -139,6 +138,7 @@ fn chrono_from_untis_time(value: u16) -> NaiveTime {
}

#[cfg(test)]
#[allow(clippy::zero_prefixed_literal)]
mod tests {
use super::*;
use chrono::Weekday;
Expand Down
7 changes: 2 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use reqwest;
use serde_json;
use std;
use std::convert::From;
use std::fmt::{self, Display, Formatter};

Expand Down Expand Up @@ -28,8 +25,8 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
let msg = match self {
Self::Reqwest(err) => format!("Reqwest error: {}", err.to_string()),
Self::Serde(err) => format!("Serde Error: {}", err.to_string()),
Self::Reqwest(err) => format!("Reqwest error: {}", err),
Self::Serde(err) => format!("Serde Error: {}", err),
Self::Http(status) => format!("HTTP Error: {}", status),
Self::Rpc(error) => format!("RPC Error: {} {}", error.code, error.message),
Self::NotFound => String::from("Resource not found"),
Expand Down
2 changes: 1 addition & 1 deletion src/jsonrpc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error;
use serde::{de::DeserializeOwned, Serialize};
use serde::{de::DeserializeOwned, Deserialize, Serialize};

/// Error codes contained in [Untis API errors](Error).
/// The underlying integer can be accessed using [code.as_isize()](Self::as_isize()).
Expand Down
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
//! ```
//! For more examples, see the `examples/` directory.
#[macro_use]
extern crate serde_derive;

mod client;
mod datetime;
mod error;
Expand Down
1 change: 1 addition & 0 deletions src/params.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{datetime::Date, ElementType};
use serde::Serialize;

#[derive(Serialize)]
#[serde(untagged)]
Expand Down
9 changes: 4 additions & 5 deletions src/resources.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::datetime::{Date, Time};
use serde::de::Deserialize;
use serde_repr::{Deserialize_repr, Serialize_repr};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// The different types of elements that exist in the Untis API.
#[derive(Serialize_repr, Deserialize_repr, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[derive(Serialize, Deserialize, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[repr(u8)]
pub enum ElementType {
Class = 1,
Expand Down Expand Up @@ -346,7 +345,7 @@ impl<'de> Deserialize<'de> for LessonCode {
Ok(match String::deserialize(deserializer)?.as_str() {
"irregular" => LessonCode::Irregular,
"cancelled" => LessonCode::Cancelled,
"regular" | _ => LessonCode::Regular,
_ => LessonCode::Regular,
})
}
}
Expand All @@ -369,7 +368,7 @@ impl<'de> Deserialize<'de> for LessonType {
"sb" => LessonType::Standby,
"bs" => LessonType::BreakSupervision,
"ex" => LessonType::Exam,
"ls" | _ => LessonType::Lesson,
_ => LessonType::Lesson,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/schools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn get_by_name(name: &str) -> Result<School, Error> {
}

fn get_first(mut list: Vec<School>) -> Result<School, Error> {
if list.len() == 0 {
if list.is_empty() {
Err(Error::NotFound)
} else {
Ok(list.swap_remove(0))
Expand Down

0 comments on commit 4f49fc4

Please sign in to comment.