Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: asyncClosure field in ConvertOptions #19

Closed
SARDONYX-sard opened this issue Nov 2, 2023 · 1 comment
Closed

[Feature]: asyncClosure field in ConvertOptions #19

SARDONYX-sard opened this issue Nov 2, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@SARDONYX-sard
Copy link
Owner

Expected behavior

I wanted to put the conversion option progress report function in a field, but I couldn't.

  • async_closure.rs
use core::future::Future;
use core::marker::PhantomData;

#[derive(Default, Debug)]
pub struct AsyncClosure<I, F, Fut, T>
where
    F: FnMut(I) -> Fut,
    Fut: Future<Output = T> + Send + 'static,
    T: Send + 'static,
{
    async_fn: Option<F>,
    _p: PhantomData<fn(I) -> Fut>,
}

impl<I, F, Fut, T> AsyncClosure<I, F, Fut, T>
where
    F: FnMut(I) -> Fut,
    Fut: Future<Output = T> + Send + 'static,
    T: Send + 'static,
{
    pub const fn new(async_fn: F) -> Self {
        Self {
            async_fn: Some(async_fn),
            _p: std::marker::PhantomData,
        }
    }

    pub fn apply(&mut self, x: I) -> Fut {
        match self.async_fn.as_mut() {
            Some(f) => f(x),
            None => async {},
        }
    }
}
  • mod.rs
use std::future::Future;
use std::path::{Path, PathBuf};
use tokio::fs;
use tokio::io::{self, AsyncReadExt, AsyncWriteExt};
use tokio_stream::StreamExt;
use tracing::trace;

pub use mapping_table::read_mapping_table;
pub use sequential::convert_dar_to_oar;

#[derive(Debug, Default)]
pub struct ConvertOptions<'a, P: AsRef<Path>, I, F, Fut, T>
where
    F: FnMut(I) -> Fut,
    Fut: Future<Output = T> + Send + 'static,
    T: Send + 'static,
{
    /// DAR source dir path
    pub dar_dir: P,
    /// OAR destination dir path(If not, it is inferred from src)
    pub oar_dir: Option<PathBuf>,
    /// mod name in config.json & directory name(If not, it is inferred from src)
    pub mod_name: Option<&'a str>,
    /// mod author in config.json
    pub author: Option<&'a str>,
    /// path to section name table
    pub section_table: Option<HashMap<String, String>>,
    /// path to section name table(For _1st_person)
    pub section_1person_table: Option<HashMap<String, String>>,
    /// After converting to OAR, add mohidden to the DAR directory before conversion to treat it as a hidden directory. (for MO2 users)
    pub hide_dar: bool,
    pub async_fn: AsyncClosure< I, F, Fut, T>,
}

other

No response

@SARDONYX-sard SARDONYX-sard added the enhancement New feature or request label Nov 2, 2023
@SARDONYX-sard
Copy link
Owner Author

I couldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant