aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/ast_to_gemtext.rs5
-rw-r--r--examples/request_to_gemtext_from_ast.rs15
-rw-r--r--rustfmt.toml24
-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
-rw-r--r--tests/ast.rs43
-rw-r--r--tests/convert.rs8
-rw-r--r--tests/meta.rs14
17 files changed, 111 insertions, 209 deletions
diff --git a/examples/ast_to_gemtext.rs b/examples/ast_to_gemtext.rs
index 5ceef21..4b96893 100644
--- a/examples/ast_to_gemtext.rs
+++ b/examples/ast_to_gemtext.rs
@@ -46,8 +46,5 @@ This is more text after a blank line.
That was a link without text."#;
fn main() {
- println!(
- "{}",
- germ::ast::Ast::from_string(EXAMPLE_GEMTEXT).to_gemtext()
- );
+ println!("{}", germ::ast::Ast::from_string(EXAMPLE_GEMTEXT).to_gemtext());
}
diff --git a/examples/request_to_gemtext_from_ast.rs b/examples/request_to_gemtext_from_ast.rs
index 174abcf..2127433 100644
--- a/examples/request_to_gemtext_from_ast.rs
+++ b/examples/request_to_gemtext_from_ast.rs
@@ -18,14 +18,13 @@
fn main() {
match germ::request::request(&url::Url::parse("gemini://fuwn.me/").unwrap()) {
- Ok(response) =>
- println!(
- "{}",
- germ::ast::Ast::from_string(
- &*response.content().clone().unwrap_or_else(|| "".to_string())
- )
- .to_gemtext()
- ),
+ Ok(response) => println!(
+ "{}",
+ germ::ast::Ast::from_string(
+ &*response.content().clone().unwrap_or_else(|| "".to_string())
+ )
+ .to_gemtext()
+ ),
Err(_) => {}
}
}
diff --git a/rustfmt.toml b/rustfmt.toml
index 1dd4c90..5ad42f8 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,30 +1,26 @@
-condense_wildcard_suffixes = true
edition = "2021"
-enum_discrim_align_threshold = 20
+enum_discrim_align_threshold = 40
# error_on_line_overflow = true
# error_on_unformatted = true
fn_single_line = true
-force_multiline_blocks = true
format_code_in_doc_comments = true
format_macro_matchers = true
format_strings = true
-imports_layout = "HorizontalVertical"
-license_template_path = ".license_template"
-max_width = 80
+inline_attribute_width = 80
match_arm_blocks = false
-imports_granularity = "Crate"
+max_width = 80
+imports_granularity = "One"
+merge_imports = true
newline_style = "Unix"
-normalize_comments = true
normalize_doc_attributes = true
+overflow_delimited_expr = true
reorder_impl_items = true
group_imports = "StdExternalCrate"
-reorder_modules = true
-report_fixme = "Always"
-# report_todo = "Always"
-struct_field_align_threshold = 20
-struct_lit_single_line = false
+required_version = "1.5.2"
+struct_field_align_threshold = 40
tab_spaces = 2
use_field_init_shorthand = true
+use_small_heuristics = "Max"
use_try_shorthand = true
-where_single_line = true
+version = "Two"
wrap_comments = true
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;
diff --git a/tests/ast.rs b/tests/ast.rs
index 7c6dc36..6d1f545 100644
--- a/tests/ast.rs
+++ b/tests/ast.rs
@@ -51,49 +51,34 @@ That was a link without text."#;
#[test]
fn build_multi_line_list_with_text() {
- assert_eq!(
- *Ast::from_string("* item1\n* 2\nhi text").inner(),
- vec![
- Node::List(vec!["item1".to_string(), "2".to_string()]),
- Node::Text("hi text".to_string()),
- ],
- );
+ assert_eq!(*Ast::from_string("* item1\n* 2\nhi text").inner(), vec![
+ Node::List(vec!["item1".to_string(), "2".to_string()]),
+ Node::Text("hi text".to_string()),
+ ],);
}
#[test]
fn build_multi_line_vec() {
- assert_eq!(
- *Ast::from_string("=> /test hi\nhi there\n> hi").inner(),
- vec![
- Node::Link {
- to: "/test".to_string(),
- text: Some("hi".to_string()),
- },
- Node::Text("hi there".to_string()),
- Node::Blockquote("hi".to_string()),
- ],
- );
+ assert_eq!(*Ast::from_string("=> /test hi\nhi there\n> hi").inner(), vec![
+ Node::Link { to: "/test".to_string(), text: Some("hi".to_string()) },
+ Node::Text("hi there".to_string()),
+ Node::Blockquote("hi".to_string()),
+ ],);
}
#[test]
fn build_single_0th_from_vec() {
- assert_eq!(
- Ast::from_string("=> /test hi").inner(),
- &vec![Node::Link {
- to: "/test".to_string(),
- text: Some("hi".to_string()),
- }],
- );
+ assert_eq!(Ast::from_string("=> /test hi").inner(), &vec![Node::Link {
+ to: "/test".to_string(),
+ text: Some("hi".to_string()),
+ }],);
}
#[test]
fn build_single_element() {
assert_eq!(
Ast::from_string("=> /test hi").inner().get(0).unwrap(),
- &Node::Link {
- to: "/test".to_string(),
- text: Some("hi".to_string()),
- },
+ &Node::Link { to: "/test".to_string(), text: Some("hi".to_string()) },
);
}
diff --git a/tests/convert.rs b/tests/convert.rs
index aad7ac4..afff5bc 100644
--- a/tests/convert.rs
+++ b/tests/convert.rs
@@ -20,8 +20,7 @@
mod test {
use germ::{
convert::{from_string, Target},
- gemini_to_html,
- gemini_to_md,
+ gemini_to_html, gemini_to_md,
};
#[test]
@@ -31,10 +30,7 @@ mod test {
#[test]
fn convert_from_string_to_html_multi_line() {
- assert_eq!(
- from_string("hi\n# hi", &Target::HTML),
- "<p>hi</p><h1>hi</h1>",
- );
+ assert_eq!(from_string("hi\n# hi", &Target::HTML), "<p>hi</p><h1>hi</h1>",);
}
#[test]
diff --git a/tests/meta.rs b/tests/meta.rs
index 70c8adc..7c555de 100644
--- a/tests/meta.rs
+++ b/tests/meta.rs
@@ -47,20 +47,14 @@ mod test {
fn meta_to_string_without_parameters() {
let original_string = "text/gemini";
- assert_eq!(
- Meta::from_string(original_string).to_string(),
- original_string
- );
+ assert_eq!(Meta::from_string(original_string).to_string(), original_string);
}
#[test]
fn meta_to_string_with_parameters() {
let original_string = "text/gemini; hi=2; hi2=string=2";
- assert_eq!(
- Meta::from_string(original_string).to_string(),
- original_string
- );
+ assert_eq!(Meta::from_string(original_string).to_string(), original_string);
}
#[test]
@@ -92,9 +86,7 @@ mod test {
#[test]
fn meta_to_map_length() {
assert_eq!(
- Meta::from_string("text/gemini; hi=2; hi2=string=2")
- .parameters()
- .len(),
+ Meta::from_string("text/gemini; hi=2; hi2=string=2").parameters().len(),
2,
);
}