aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-05-18 06:24:50 +0000
committerFuwn <[email protected]>2023-05-18 06:24:50 +0000
commit56f53ddca0135e17708af585bfb50144d6836f55 (patch)
tree1d5beea4c266a7d9bdd50fe4750540d618b0b160 /src
parentfix: improve macro hygiene (diff)
downloadgerm-56f53ddca0135e17708af585bfb50144d6836f55.tar.xz
germ-56f53ddca0135e17708af585bfb50144d6836f55.zip
fmt: update rustfmt.toml
Diffstat (limited to 'src')
-rw-r--r--src/ast.rs6
-rw-r--r--src/ast/container.rs76
-rw-r--r--src/convert.rs3
-rw-r--r--src/convert/html.rs31
-rw-r--r--src/convert/markdown.rs39
-rw-r--r--src/lib.rs15
-rw-r--r--src/meta.rs10
-rw-r--r--src/request.rs11
-rw-r--r--src/request/response.rs6
-rw-r--r--src/request/sync.rs7
-rw-r--r--src/request/verifier.rs7
11 files changed, 74 insertions, 137 deletions
diff --git a/src/ast.rs b/src/ast.rs
index 8c00b52..cec8c89 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -21,8 +21,6 @@
mod container;
mod node;
-#[cfg(feature = "macros")]
-mod macros;
+#[cfg(feature = "macros")] mod macros;
-pub use container::Ast;
-pub use node::Node;
+pub use {container::Ast, node::Node};
diff --git a/src/ast/container.rs b/src/ast/container.rs
index acb8894..0e3337d 100644
--- a/src/ast/container.rs
+++ b/src/ast/container.rs
@@ -82,9 +82,7 @@ impl Ast {
));
}
- Self {
- inner: ast
- }
+ Self { inner: ast }
}
#[must_use]
@@ -94,45 +92,31 @@ impl Ast {
for node in &self.inner {
match node {
Node::Text(text) => gemtext.push_str(&format!("{text}\n")),
- Node::Link {
+ Node::Link { to, text } => gemtext.push_str(&format!(
+ "=> {}{}\n",
to,
- text,
- } =>
- gemtext.push_str(&format!(
- "=> {}{}\n",
- to,
- text
- .clone()
- .map_or_else(String::new, |text| format!(" {text}")),
- )),
- Node::Heading {
- level,
- text,
- } =>
- gemtext.push_str(&format!(
- "{} {}\n",
- match level {
- 1 => "#",
- 2 => "##",
- 3 => "###",
- _ => "",
- },
- text
- )),
- Node::List(items) =>
- gemtext.push_str(&format!(
- "{}\n",
- items
- .iter()
- .map(|i| format!("* {i}"))
- .collect::<Vec<String>>()
- .join("\n"),
- )),
+ text.clone().map_or_else(String::new, |text| format!(" {text}")),
+ )),
+ Node::Heading { level, text } => gemtext.push_str(&format!(
+ "{} {}\n",
+ match level {
+ 1 => "#",
+ 2 => "##",
+ 3 => "###",
+ _ => "",
+ },
+ text
+ )),
+ Node::List(items) => gemtext.push_str(&format!(
+ "{}\n",
+ items
+ .iter()
+ .map(|i| format!("* {i}"))
+ .collect::<Vec<String>>()
+ .join("\n"),
+ )),
Node::Blockquote(text) => gemtext.push_str(&format!("> {text}\n")),
- Node::PreformattedText {
- alt_text,
- text,
- } =>
+ Node::PreformattedText { alt_text, text } =>
gemtext.push_str(&format!(
"```{}\n{}```\n",
alt_text.clone().unwrap_or_default(),
@@ -190,11 +174,7 @@ impl Ast {
text: {
let rest = split.collect::<Vec<String>>().join(" ");
- if rest.is_empty() {
- None
- } else {
- Some(rest)
- }
+ if rest.is_empty() { None } else { Some(rest) }
},
});
@@ -263,11 +243,7 @@ impl Ast {
}
} else {
nodes.push(Node::PreformattedText {
- alt_text: if alt_text.is_empty() {
- None
- } else {
- Some(alt_text)
- },
+ alt_text: if alt_text.is_empty() { None } else { Some(alt_text) },
text: preformatted,
});
diff --git a/src/convert.rs b/src/convert.rs
index 22329d0..f9262f7 100644
--- a/src/convert.rs
+++ b/src/convert.rs
@@ -23,8 +23,7 @@ use crate::ast::Ast;
mod html;
mod markdown;
-#[cfg(feature = "macros")]
-mod macros;
+#[cfg(feature = "macros")] mod macros;
/// Different targets to convert Gemtext to
#[derive(Clone)]
diff --git a/src/convert/html.rs b/src/convert/html.rs
index 581cbab..a6b0426 100644
--- a/src/convert/html.rs
+++ b/src/convert/html.rs
@@ -26,20 +26,14 @@ pub fn convert(source: &[Node]) -> String {
for node in source {
match node {
Node::Text(text) => html.push_str(&format!("<p>{text}</p>")),
- Node::Link {
- to,
- text,
- } => {
+ Node::Link { to, text } => {
html.push_str(&format!(
"<a href=\"{}\">{}</a><br>",
to,
text.clone().unwrap_or_else(|| to.clone())
));
}
- Node::Heading {
- level,
- text,
- } => {
+ Node::Heading { level, text } => {
html.push_str(&format!(
"<{}>{}</{0}>",
match level {
@@ -51,20 +45,17 @@ pub fn convert(source: &[Node]) -> String {
text
));
}
- Node::List(items) =>
- html.push_str(&format!(
- "<ul>{}</ul>",
- items
- .iter()
- .map(|i| format!("<li>{i}</li>"))
- .collect::<Vec<String>>()
- .join("\n")
- )),
+ Node::List(items) => html.push_str(&format!(
+ "<ul>{}</ul>",
+ items
+ .iter()
+ .map(|i| format!("<li>{i}</li>"))
+ .collect::<Vec<String>>()
+ .join("\n")
+ )),
Node::Blockquote(text) =>
html.push_str(&format!("<blockquote>{text}</blockquote>")),
- Node::PreformattedText {
- text, ..
- } => {
+ Node::PreformattedText { text, .. } => {
html.push_str(&format!("<pre>{text}</pre>"));
}
Node::Whitespace => {}
diff --git a/src/convert/markdown.rs b/src/convert/markdown.rs
index 3401940..71e54f2 100644
--- a/src/convert/markdown.rs
+++ b/src/convert/markdown.rs
@@ -26,18 +26,11 @@ pub fn convert(source: &[Node]) -> String {
for node in source {
match node {
Node::Text(text) => markdown.push_str(&format!("{text}\n")),
- Node::Link {
- to,
- text,
- } =>
- markdown.push_str(&text.clone().map_or_else(
- || format!("<{to}>\n"),
- |text| format!("[{text}]({to})\n"),
- )),
- Node::Heading {
- level,
- text,
- } => {
+ Node::Link { to, text } => markdown.push_str(&text.clone().map_or_else(
+ || format!("<{to}>\n"),
+ |text| format!("[{text}]({to})\n"),
+ )),
+ Node::Heading { level, text } => {
markdown.push_str(&format!(
"{} {}\n",
match level {
@@ -49,20 +42,16 @@ pub fn convert(source: &[Node]) -> String {
text
));
}
- Node::List(items) =>
- markdown.push_str(&format!(
- "{}\n",
- items
- .iter()
- .map(|i| format!("- {i}"))
- .collect::<Vec<String>>()
- .join("\n"),
- )),
+ Node::List(items) => markdown.push_str(&format!(
+ "{}\n",
+ items
+ .iter()
+ .map(|i| format!("- {i}"))
+ .collect::<Vec<String>>()
+ .join("\n"),
+ )),
Node::Blockquote(text) => markdown.push_str(&format!("> {text}\n")),
- Node::PreformattedText {
- alt_text,
- text,
- } => {
+ Node::PreformattedText { alt_text, text } => {
markdown.push_str(&format!(
"```{}\n{}```\n",
alt_text.clone().unwrap_or_default(),
diff --git a/src/lib.rs b/src/lib.rs
index 6bdebcc..b7156a1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,17 +29,12 @@
)]
#![recursion_limit = "128"]
-#[cfg(feature = "ast")]
-pub mod ast;
+#[cfg(feature = "ast")] pub mod ast;
-#[cfg(feature = "convert")]
-pub mod convert;
+#[cfg(feature = "convert")] pub mod convert;
-#[cfg(feature = "request")]
-pub mod request;
+#[cfg(feature = "request")] pub mod request;
-#[cfg(feature = "meta")]
-pub mod meta;
+#[cfg(feature = "meta")] pub mod meta;
-#[cfg(feature = "quick")]
-pub mod quick;
+#[cfg(feature = "quick")] pub mod quick;
diff --git a/src/meta.rs b/src/meta.rs
index 2a210a0..8962d7f 100644
--- a/src/meta.rs
+++ b/src/meta.rs
@@ -89,9 +89,8 @@ impl Meta {
let mut parameters = HashMap::new();
for parameter in metas {
- let key_value = parameter
- .trim_start()
- .split_at(parameter.find('=').unwrap_or(0));
+ let key_value =
+ parameter.trim_start().split_at(parameter.find('=').unwrap_or(0));
parameters.insert(
key_value.0.to_string().replace('=', ""),
@@ -99,10 +98,7 @@ impl Meta {
);
}
- Self {
- mime,
- parameters,
- }
+ Self { mime, parameters }
}
/// Obtain non-mutable access to the mime of the `Meta`
diff --git a/src/request.rs b/src/request.rs
index 2c7c273..97aa954 100644
--- a/src/request.rs
+++ b/src/request.rs
@@ -22,14 +22,12 @@ mod response;
mod status;
mod verifier;
-#[cfg(feature = "sync")]
-pub mod sync;
+#[cfg(feature = "sync")] pub mod sync;
use std::io::{Read, Write};
-pub use response::Response;
-pub use status::Status;
pub(crate) use verifier::GermVerifier;
+pub use {response::Response, status::Status};
/// Make a request to a Gemini server. The `url` **should** be prefixed with a
/// scheme (e.g. "gemini://").
@@ -69,8 +67,5 @@ pub fn request(url: &url::Url) -> anyhow::Result<Response> {
tls.read_to_end(&mut plain_text)?;
- Ok(Response::new(
- &plain_text,
- tls.conn.negotiated_cipher_suite(),
- ))
+ Ok(Response::new(&plain_text, tls.conn.negotiated_cipher_suite()))
}
diff --git a/src/request/response.rs b/src/request/response.rs
index 4c822e1..f0119d0 100644
--- a/src/request/response.rs
+++ b/src/request/response.rs
@@ -16,11 +16,7 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::borrow::Cow;
-
-use rustls::SupportedCipherSuite;
-
-use crate::request::Status;
+use {crate::request::Status, rustls::SupportedCipherSuite, std::borrow::Cow};
#[derive(Debug, Clone)]
pub struct Response {
diff --git a/src/request/sync.rs b/src/request/sync.rs
index f3cd7d1..56950fb 100644
--- a/src/request/sync.rs
+++ b/src/request/sync.rs
@@ -16,9 +16,10 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use tokio::io::{AsyncReadExt, AsyncWriteExt};
-
-use crate::request::Response;
+use {
+ crate::request::Response,
+ tokio::io::{AsyncReadExt, AsyncWriteExt},
+};
/// Make a request to a Gemini server
///
diff --git a/src/request/verifier.rs b/src/request/verifier.rs
index b0120bd..a858b72 100644
--- a/src/request/verifier.rs
+++ b/src/request/verifier.rs
@@ -16,9 +16,10 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::time::SystemTime;
-
-use rustls::{client, client::ServerCertVerified, Certificate};
+use {
+ rustls::{client, client::ServerCertVerified, Certificate},
+ std::time::SystemTime,
+};
#[allow(clippy::module_name_repetitions)]
pub struct GermVerifier;