Skip to content

Commit

Permalink
Remove unneeded derive(Serialize)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 11, 2024
1 parent 03320d5 commit 76ba5be
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 67 deletions.
6 changes: 3 additions & 3 deletions src/web/build_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use chrono::{DateTime, Utc};
use futures_util::TryStreamExt;
use rinja::Template;
use semver::Version;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct BuildDetails {
id: i32,
rustc_version: Option<String>,
Expand All @@ -32,7 +32,7 @@ pub(crate) struct BuildDetails {

#[derive(Template)]
#[template(path = "crate/build_details.html")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct BuildDetailsPage {
metadata: MetaData,
build_details: BuildDetails,
Expand Down
8 changes: 3 additions & 5 deletions src/web/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ use constant_time_eq::constant_time_eq;
use http::StatusCode;
use rinja::Template;
use semver::Version;
use serde::Serialize;
use serde_json::json;
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct Build {
id: i32,
rustc_version: Option<String>,
Expand All @@ -45,7 +43,7 @@ pub(crate) struct Build {

#[derive(Template)]
#[template(path = "crate/builds.html")]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone)]
struct BuildsPage {
metadata: MetaData,
builds: Vec<Build>,
Expand Down Expand Up @@ -235,7 +233,7 @@ pub(crate) async fn build_trigger_rebuild_handler(
.await
.map_err(|e| JsonAxumNope(e.into()))?;

Ok((StatusCode::CREATED, Json(json!({}))))
Ok((StatusCode::CREATED, Json(serde_json::json!({}))))
}

async fn get_builds(
Expand Down
29 changes: 8 additions & 21 deletions src/web/crate_details.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{markdown, match_version, MetaData};
use super::{match_version, MetaData};
use crate::registry_api::OwnerKind;
use crate::utils::{get_correct_docsrs_style_file, report_error};
use crate::web::rustdoc::RustdocHtmlParams;
Expand Down Expand Up @@ -27,22 +27,19 @@ use log::warn;
use rinja::Template;
use semver::Version;
use serde::Deserialize;
use serde::{ser::Serializer, Serialize};
use serde_json::Value;
use std::sync::Arc;

// TODO: Add target name and versions

#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct CrateDetails {
pub(crate) name: String,
pub(crate) version: Version,
pub(crate) description: Option<String>,
pub(crate) owners: Vec<(String, String, OwnerKind)>,
pub(crate) dependencies: Option<Value>,
#[serde(serialize_with = "optional_markdown")]
readme: Option<String>,
#[serde(serialize_with = "optional_markdown")]
rustdoc: Option<String>, // this is description_long in database
release_time: Option<DateTime<Utc>>,
build_status: BuildStatus,
Expand Down Expand Up @@ -71,25 +68,15 @@ pub(crate) struct CrateDetails {
pub(crate) release_id: i32,
}

#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct RepositoryMetadata {
stars: i32,
forks: i32,
issues: i32,
name: Option<String>,
}

fn optional_markdown<S>(markdown: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
markdown
.as_ref()
.map(|markdown| markdown::render(markdown))
.serialize(serializer)
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub(crate) struct Release {
pub id: i32,
pub version: semver::Version,
Expand Down Expand Up @@ -425,7 +412,7 @@ pub(crate) async fn releases_for_crate(

#[derive(Template)]
#[template(path = "crate/details.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct CrateDetailsPage {
details: CrateDetails,
csp_nonce: String,
Expand Down Expand Up @@ -507,7 +494,7 @@ pub(crate) async fn crate_details_handler(

#[derive(Template)]
#[template(path = "rustdoc/releases.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct ReleaseList {
releases: Vec<Release>,
crate_name: String,
Expand Down Expand Up @@ -600,7 +587,7 @@ pub(crate) async fn get_all_releases(
Ok(res.into_response())
}

#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct ShortMetadata {
name: String,
version: Version,
Expand All @@ -617,7 +604,7 @@ impl ShortMetadata {

#[derive(Template)]
#[template(path = "rustdoc/platforms.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct PlatformList {
metadata: ShortMetadata,
inner_path: String,
Expand Down
3 changes: 1 addition & 2 deletions src/web/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ use crate::{
use anyhow::anyhow;
use axum::response::IntoResponse;
use rinja::Template;
use serde::Serialize;
use std::collections::{HashMap, VecDeque};

const DEFAULT_NAME: &str = "default";

#[derive(Template)]
#[template(path = "crate/features.html")]
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone)]
struct FeaturesPage {
metadata: MetaData,
features: Option<Vec<Feature>>,
Expand Down
7 changes: 3 additions & 4 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use error::AxumNope;
use page::TemplateData;
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use semver::{Version, VersionReq};
use serde::Serialize;
use serde_with::{DeserializeFromStr, SerializeDisplay};
use std::{
borrow::{Borrow, Cow},
Expand Down Expand Up @@ -618,7 +617,8 @@ where
}

/// MetaData used in header
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(test, derive(serde::Serialize))]
pub(crate) struct MetaData {
pub(crate) name: String,
/// The exact version of the release being shown.
Expand Down Expand Up @@ -721,13 +721,12 @@ impl MetaData {

#[derive(Template)]
#[template(path = "error.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct AxumErrorPage {
/// The title of the page
pub title: &'static str,
/// The error message, displayed as a description
pub message: Cow<'static, str>,
#[serde(skip)]
pub status: StatusCode,
pub csp_nonce: String,
}
Expand Down
14 changes: 6 additions & 8 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ async fn get_search_results(

#[derive(Template)]
#[template(path = "core/home.html")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct HomePage {
recent_releases: Vec<Release>,
csp_nonce: String,
Expand Down Expand Up @@ -330,7 +330,7 @@ pub(crate) async fn home_page(mut conn: DbConnection) -> AxumResult<impl IntoRes

#[derive(Template)]
#[template(path = "releases/feed.xml")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct ReleaseFeed {
recent_releases: Vec<Release>,
csp_nonce: String,
Expand All @@ -352,7 +352,7 @@ pub(crate) async fn releases_feed_handler(mut conn: DbConnection) -> AxumResult<

#[derive(Template)]
#[template(path = "releases/releases.html")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct ViewReleases {
releases: Vec<Release>,
description: String,
Expand All @@ -372,8 +372,7 @@ impl ViewReleases {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "kebab-case")]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub(crate) enum ReleaseType {
Recent,
Stars,
Expand Down Expand Up @@ -496,7 +495,7 @@ pub(crate) async fn owner_handler(Path(owner): Path<String>) -> AxumResult<impl

#[derive(Template)]
#[template(path = "releases/search_results.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
pub(super) struct Search {
pub(super) title: String,
pub(super) releases: Vec<Release>,
Expand All @@ -506,7 +505,6 @@ pub(super) struct Search {
pub(super) next_page_link: Option<String>,
/// This should always be `ReleaseType::Search`
pub(super) release_type: ReleaseType,
#[serde(skip)]
pub(super) status: http::StatusCode,
pub(super) csp_nonce: String,
}
Expand Down Expand Up @@ -732,7 +730,7 @@ pub(crate) async fn search_handler(

#[derive(Template)]
#[template(path = "releases/activity.html")]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[derive(Debug, Clone, PartialEq)]
struct ReleaseActivity {
description: &'static str,
dates: Vec<String>,
Expand Down
2 changes: 1 addition & 1 deletion src/web/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub(super) fn build_axum_routes() -> AxumRouter {
get_internal(|| async {
#[derive(Template)]
#[template(path = "storage-change-detection.html")]
#[derive(Debug, Clone, serde::Serialize)]
#[derive(Debug, Clone)]
struct StorageChangeDetection {
csp_nonce: String,
}
Expand Down
14 changes: 2 additions & 12 deletions src/web/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use axum::{
use lol_html::errors::RewritingError;
use once_cell::sync::Lazy;
use semver::Version;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
Expand Down Expand Up @@ -257,12 +257,10 @@ pub(crate) async fn rustdoc_redirector_handler(
}
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone)]
pub struct RustdocPage {
pub latest_path: String,
pub permalink_path: String,
pub latest_version: String,
pub target: String,
pub inner_path: String,
// true if we are displaying the latest version of the crate, regardless
// of whether the URL specifies a version number or the string "latest."
Expand Down Expand Up @@ -604,12 +602,6 @@ pub(crate) async fn rustdoc_html_server_handler(
.recently_accessed_releases
.record(krate.crate_id, krate.release_id, target);

let target = if target.is_empty() {
String::new()
} else {
format!("{target}/")
};

// Build the page of documentation,
templates
.render_in_threadpool({
Expand All @@ -619,8 +611,6 @@ pub(crate) async fn rustdoc_html_server_handler(
Ok(RustdocPage {
latest_path,
permalink_path,
latest_version: latest_version.to_string(),
target,
inner_path,
is_latest_version,
is_latest_url: params.version.is_latest(),
Expand Down
9 changes: 4 additions & 5 deletions src/web/sitemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ use axum::{extract::Extension, http::StatusCode, response::IntoResponse};
use chrono::{TimeZone, Utc};
use futures_util::stream::TryStreamExt;
use rinja::Template;
use serde::Serialize;
use std::sync::Arc;

/// sitemap index
#[derive(Template)]
#[template(path = "core/sitemapindex.xml")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct SitemapIndexXml {
sitemaps: Vec<char>,
csp_nonce: String,
Expand All @@ -41,7 +40,7 @@ pub(crate) async fn sitemapindex_handler() -> impl IntoResponse {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct SitemapRow {
crate_name: String,
last_modified: String,
Expand All @@ -51,7 +50,7 @@ struct SitemapRow {
/// The sitemap
#[derive(Template)]
#[template(path = "core/sitemap.xml")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct SitemapXml {
releases: Vec<SitemapRow>,
csp_nonce: String,
Expand Down Expand Up @@ -112,7 +111,7 @@ pub(crate) async fn sitemap_handler(

#[derive(Template)]
#[template(path = "core/about/builds.html")]
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct AboutBuilds {
/// The current version of rustc that docs.rs is using to build crates
rustc_version: Option<String>,
Expand Down
Loading

0 comments on commit 76ba5be

Please sign in to comment.