use FnOnce for callback function

This commit is contained in:
yggverse 2025-01-17 07:33:10 +02:00
parent 65237abee0
commit 7315f57a4b
3 changed files with 7 additions and 19 deletions

View File

@ -42,7 +42,7 @@ impl Client {
/// Begin new request /// Begin new request
/// * the `query` as string, to support system routes (e.g. `source:` prefix) /// * the `query` as string, to support system routes (e.g. `source:` prefix)
pub fn request_async(&self, request: &str, callback: impl Fn(Response) + 'static) { pub fn request_async(&self, request: &str, callback: impl FnOnce(Response) + 'static) {
// Update client status // Update client status
self.status.replace(Status::Request { self.status.replace(Status::Request {
time: now(), time: now(),
@ -52,7 +52,7 @@ impl Client {
self.driver.feature_async( self.driver.feature_async(
Feature::from_string(request), Feature::from_string(request),
self.new_cancellable(), self.new_cancellable(),
Rc::new(callback), callback,
); );
} }

View File

@ -65,7 +65,7 @@ impl Driver {
&self, &self,
feature: Feature, feature: Feature,
cancellable: Cancellable, cancellable: Cancellable,
callback: Rc<impl Fn(Response) + 'static>, callback: impl FnOnce(Response) + 'static,
) { ) {
match feature { match feature {
Feature::Download { request } => match request { Feature::Download { request } => match request {
@ -98,13 +98,7 @@ impl Driver {
uri.clone(), uri.clone(),
cancellable.clone(), cancellable.clone(),
move |result| { move |result| {
gemini::handle( gemini::handle(result, uri.clone(), cancellable.clone(), false, callback)
result,
uri.clone(),
cancellable.clone(),
false,
callback.clone(),
)
}, },
), ),
Request::Titan { .. } => todo!(), Request::Titan { .. } => todo!(),
@ -117,13 +111,7 @@ impl Driver {
uri.clone(), uri.clone(),
cancellable.clone(), cancellable.clone(),
move |result| { move |result| {
gemini::handle( gemini::handle(result, uri.clone(), cancellable.clone(), true, callback)
result,
uri.clone(),
cancellable.clone(),
true,
callback.clone(),
)
}, },
), ),
_ => callback(Response::Failure(Failure::Error { _ => callback(Response::Failure(Failure::Error {

View File

@ -14,7 +14,7 @@ pub fn request_async(
client: &Rc<ggemini::Client>, client: &Rc<ggemini::Client>,
uri: Uri, uri: Uri,
cancellable: Cancellable, cancellable: Cancellable,
callback: impl Fn(Result<ggemini::client::Response, ggemini::client::Error>) + 'static, callback: impl FnOnce(Result<ggemini::client::Response, ggemini::client::Error>) + 'static,
) { ) {
let request = uri.to_string(); let request = uri.to_string();
client.request_async( client.request_async(
@ -41,7 +41,7 @@ pub fn handle(
base: Uri, base: Uri,
cancellable: Cancellable, cancellable: Cancellable,
is_source_request: bool, // @TODO yet partial implementation is_source_request: bool, // @TODO yet partial implementation
callback: Rc<impl Fn(Response) + 'static>, callback: impl FnOnce(Response) + 'static,
) { ) {
use ggemini::client::connection::response::{data::Text, meta::Status}; use ggemini::client::connection::response::{data::Text, meta::Status};
match result { match result {