Skip to content

Commit

Permalink
Merge pull request #12 from thoiberg/more-idiomatic-rust
Browse files Browse the repository at this point in the history
Accept &str instead of String
  • Loading branch information
thoiberg authored Jul 3, 2023
2 parents cf58ee0 + 6451339 commit e0f376a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions backend/src/api/bunpro/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ async fn get_review_queue() -> anyhow::Result<StudyQueue> {
.await?
.text()
.await
.map(serialize_response)?
.map(|body| serialize_response(&body))?
}

fn serialize_response(body: String) -> anyhow::Result<StudyQueue> {
let json = serde_json::from_str(body.as_str())?;
fn serialize_response(body: &str) -> anyhow::Result<StudyQueue> {
let json = serde_json::from_str(body)?;

Ok(json)
}
Expand All @@ -42,13 +42,13 @@ mod test_super {
#[test]
fn test_bunpro_with_reviews() {
let with_reviews = include_str!("./fixtures/bunpro_with_reviews.json");
let response = serialize_response(String::from(with_reviews));
let response = serialize_response(with_reviews);
assert!(response.is_ok());
}

#[test]
fn test_bunpro_with_no_reviews() {
let with_no_reviews = include_str!("./fixtures/bunpro_with_no_reviews.json");
assert!(serialize_response(String::from(with_no_reviews)).is_ok());
assert!(serialize_response(with_no_reviews).is_ok());
}
}
10 changes: 5 additions & 5 deletions backend/src/api/wanikani/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ async fn get_summary_data() -> anyhow::Result<WaniKaniResponse> {
.await?
.text()
.await
.map(deserialize_response)?
.map(|body| deserialize_response(&body))?
}

fn deserialize_response(response_body: String) -> anyhow::Result<WaniKaniResponse> {
let json_data = serde_json::from_str(response_body.as_str())?;
fn deserialize_response(response_body: &str) -> anyhow::Result<WaniKaniResponse> {
let json_data = serde_json::from_str(response_body)?;

Ok(json_data)
}
Expand All @@ -44,7 +44,7 @@ mod test_super {
fn test_can_deserialize_empty_reviews() {
let response_data = include_str!("./fixtures/wanikani_with_no_reviews.json");

let response = deserialize_response(response_data.into());
let response = deserialize_response(response_data);

assert!(response.is_ok());
}
Expand All @@ -53,7 +53,7 @@ mod test_super {
fn test_can_deserialize_with_reviews() {
let response_data = include_str!("./fixtures/wanikani_with_reviews.json");

let response = deserialize_response(response_data.into());
let response = deserialize_response(response_data);

assert!(response.is_ok());
}
Expand Down

0 comments on commit e0f376a

Please sign in to comment.