Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
picoHz committed Aug 14, 2024
1 parent 0245ff3 commit b71a0ff
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 43 deletions.
16 changes: 8 additions & 8 deletions taxy-api/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::{collections::HashMap, fmt::Display};
use time::OffsetDateTime;
use utoipa::{IntoParams, ToSchema};

Expand Down Expand Up @@ -28,14 +28,14 @@ impl TryFrom<u8> for LogLevel {
}
}

impl ToString for LogLevel {
fn to_string(&self) -> String {
impl Display for LogLevel {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
LogLevel::Error => "error".to_string(),
LogLevel::Warn => "warn".to_string(),
LogLevel::Info => "info".to_string(),
LogLevel::Debug => "debug".to_string(),
LogLevel::Trace => "trace".to_string(),
LogLevel::Error => write!(f, "error"),
LogLevel::Warn => write!(f, "warn"),
LogLevel::Info => write!(f, "info"),
LogLevel::Debug => write!(f, "debug"),
LogLevel::Trace => write!(f, "trace"),
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions taxy-api/src/subject_name.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::Error;
use serde::{Deserialize, Serialize};
use std::{net::IpAddr, str::FromStr};
use std::{fmt::Display, net::IpAddr, str::FromStr};

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SubjectName {
Expand Down Expand Up @@ -44,12 +44,12 @@ impl<'de> Deserialize<'de> for SubjectName {
}
}

impl ToString for SubjectName {
fn to_string(&self) -> String {
impl Display for SubjectName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::DnsName(name) => name.to_owned(),
Self::WildcardDnsName(name) => format!("*.{}", name),
Self::IPAddress(addr) => addr.to_string(),
Self::DnsName(name) => write!(f, "{}", name),
Self::WildcardDnsName(name) => write!(f, "*.{}", name),
Self::IPAddress(addr) => write!(f, "{}", addr),
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions taxy-webui/src/components/proxy_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::store::PortStore;
use crate::API_ENDPOINT;
use gloo_net::http::Request;
use std::collections::HashMap;
use std::fmt::Display;
use taxy_api::id::ShortId;
use taxy_api::proxy::{HttpProxy, ProxyKind, TcpProxy};
use taxy_api::{port::PortEntry, proxy::Proxy};
Expand All @@ -18,11 +19,11 @@ pub enum ProxyProtocol {
Tcp,
}

impl ToString for ProxyProtocol {
fn to_string(&self) -> String {
impl Display for ProxyProtocol {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProxyProtocol::Http => "HTTP / HTTPS".to_string(),
ProxyProtocol::Tcp => "TCP / TCP over TLS".to_string(),
ProxyProtocol::Http => write!(f, "HTTP / HTTPS"),
ProxyProtocol::Tcp => write!(f, "TCP / TCP over TLS"),
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions taxy-webui/src/pages/cert_list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use crate::auth::use_ensure_auth;
use crate::format::format_duration;
use crate::pages::Route;
Expand Down Expand Up @@ -27,14 +29,13 @@ pub struct CertsQuery {
pub tab: CertsTab,
}

impl ToString for CertsTab {
fn to_string(&self) -> String {
impl Display for CertsTab {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CertsTab::Server => "Server Certs",
CertsTab::Root => "Root Certs",
CertsTab::Acme => "ACME",
CertsTab::Server => write!(f, "Server Certs"),
CertsTab::Root => write!(f, "Root Certs"),
CertsTab::Acme => write!(f, "ACME"),
}
.into()
}
}

Expand Down
13 changes: 7 additions & 6 deletions taxy-webui/src/pages/new_acme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::pages::cert_list::{CertsQuery, CertsTab};
use crate::{auth::use_ensure_auth, pages::Route, API_ENDPOINT};
use gloo_net::http::Request;
use std::collections::HashMap;
use std::fmt::Display;
use taxy_api::acme::AcmeRequest;
use wasm_bindgen::{JsCast, UnwrapThrowExt};
use web_sys::HtmlSelectElement;
Expand Down Expand Up @@ -35,13 +36,13 @@ impl Provider {
}
}

impl ToString for Provider {
fn to_string(&self) -> String {
impl Display for Provider {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Provider::LetsEncrypt => "Let's Encrypt".to_string(),
Provider::GoogleTrustServices => "Google Trust Services".to_string(),
Provider::ZeroSSL => "ZeroSSL".to_string(),
Provider::Custom => "Custom".to_string(),
Provider::LetsEncrypt => write!(f, "Let's Encrypt"),
Provider::GoogleTrustServices => write!(f, "Google Trust Services"),
Provider::ZeroSSL => write!(f, "ZeroSSL"),
Provider::Custom => write!(f, "Custom"),
}
}
}
Expand Down
14 changes: 1 addition & 13 deletions taxy/src/proxy/http/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use taxy_api::{
id::ShortId,
proxy::{ProxyEntry, ProxyKind, Route, Server},
};
use tokio_rustls::rustls::pki_types::ServerName;
use tracing::error;
use url::Url;
use warp::host::Authority;
Expand Down Expand Up @@ -63,7 +62,6 @@ pub struct FilteredRoute {

#[derive(Debug)]
pub struct ParsedRoute {
pub path: String,
pub servers: Vec<ParsedServer>,
}

Expand All @@ -76,18 +74,14 @@ impl TryFrom<Route> for ParsedRoute {
.into_iter()
.map(ParsedServer::try_from)
.collect::<Result<Vec<_>, _>>()?;
Ok(Self {
path: route.path,
servers,
})
Ok(Self { servers })
}
}

#[derive(Debug)]
pub struct ParsedServer {
pub url: Url,
pub authority: Authority,
pub server_name: ServerName<'static>,
}

impl TryFrom<Server> for ParsedServer {
Expand All @@ -100,15 +94,9 @@ impl TryFrom<Server> for ParsedServer {
let hostname = server.url.hostname().ok_or(Error::InvalidServerUrl {
url: server.url.to_string(),
})?;
let server_name = ServerName::try_from(hostname)
.map_err(|_| Error::InvalidServerUrl {
url: server.url.to_string(),
})?
.to_owned();
Ok(Self {
url: server.url.into(),
authority,
server_name,
})
}
}

0 comments on commit b71a0ff

Please sign in to comment.