From 3970616451ab4336e37a7ddfdc67f51e01e55926 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sun, 24 Mar 2024 14:24:20 +0000 Subject: refactor: module for blocking, default to non-blocking --- examples/async_request.rs | 29 --------------------- examples/request.rs | 7 ++++-- examples/request_blocking.rs | 26 +++++++++++++++++++ examples/request_blocking_to_gemtext_from_ast.rs | 32 ++++++++++++++++++++++++ examples/request_to_gemtext_from_ast.rs | 30 ---------------------- 5 files changed, 63 insertions(+), 61 deletions(-) delete mode 100644 examples/async_request.rs create mode 100644 examples/request_blocking.rs create mode 100644 examples/request_blocking_to_gemtext_from_ast.rs delete mode 100644 examples/request_to_gemtext_from_ast.rs (limited to 'examples') diff --git a/examples/async_request.rs b/examples/async_request.rs deleted file mode 100644 index 604d6d4..0000000 --- a/examples/async_request.rs +++ /dev/null @@ -1,29 +0,0 @@ -// This file is part of Germ . -// Copyright (C) 2022-2022 Fuwn -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 3. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// Copyright (C) 2022-2022 Fuwn -// SPDX-License-Identifier: GPL-3.0-only - -#[tokio::main] -async fn main() { - match germ::request::sync::request( - &url::Url::parse("gemini://fuwn.me").unwrap(), - ) - .await - { - Ok(response) => println!("{:?}", response), - Err(_) => {} - } -} diff --git a/examples/request.rs b/examples/request.rs index e33710f..33de2da 100644 --- a/examples/request.rs +++ b/examples/request.rs @@ -16,8 +16,11 @@ // Copyright (C) 2022-2022 Fuwn // SPDX-License-Identifier: GPL-3.0-only -fn main() { - match germ::request::request(&url::Url::parse("gemini://fuwn.me").unwrap()) { +#[tokio::main] +async fn main() { + match germ::request::request(&url::Url::parse("gemini://fuwn.me").unwrap()) + .await + { Ok(response) => println!("{:?}", response), Err(_) => {} } diff --git a/examples/request_blocking.rs b/examples/request_blocking.rs new file mode 100644 index 0000000..fed1c41 --- /dev/null +++ b/examples/request_blocking.rs @@ -0,0 +1,26 @@ +// This file is part of Germ . +// Copyright (C) 2022-2022 Fuwn +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Copyright (C) 2022-2022 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +fn main() { + match germ::request::blocking::request( + &url::Url::parse("gemini://fuwn.me").unwrap(), + ) { + Ok(response) => println!("{:?}", response), + Err(_) => {} + } +} diff --git a/examples/request_blocking_to_gemtext_from_ast.rs b/examples/request_blocking_to_gemtext_from_ast.rs new file mode 100644 index 0000000..6abfdfb --- /dev/null +++ b/examples/request_blocking_to_gemtext_from_ast.rs @@ -0,0 +1,32 @@ +// This file is part of Germ . +// Copyright (C) 2022-2022 Fuwn +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// Copyright (C) 2022-2022 Fuwn +// SPDX-License-Identifier: GPL-3.0-only + +fn main() { + match germ::request::blocking::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() + ), + Err(_) => {} + } +} diff --git a/examples/request_to_gemtext_from_ast.rs b/examples/request_to_gemtext_from_ast.rs deleted file mode 100644 index 2127433..0000000 --- a/examples/request_to_gemtext_from_ast.rs +++ /dev/null @@ -1,30 +0,0 @@ -// This file is part of Germ . -// Copyright (C) 2022-2022 Fuwn -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 3. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// Copyright (C) 2022-2022 Fuwn -// SPDX-License-Identifier: GPL-3.0-only - -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() - ), - Err(_) => {} - } -} -- cgit v1.2.3