ruwebframe 0.1.9

a simple webframe for rust actix-web, based on rudi and rbatis.
Documentation
use crate::rudi::difactroy::find_bean_di_factroy;
use crate::rudi::{ find_bean_di_example};

#[cfg(test)]
mod tests {
    use super::*;
    use crate::rulog;
    use std::fmt::{Debug, Display};
    use std::sync::Arc;
    use crate::ruconf::find_bean_ru_config;
    use crate::rulog::ru_log;

    #[test]
    fn test_01_example() {
        let example = find_bean_di_example().unwrap();
        rulog::info2("{}", example.lock().unwrap().id);
    }
    #[test]
    fn test_02_make_di() {
        find_bean_di_factroy().unwrap().lock().unwrap().make_di();
    }

    pub fn make_di_generic<T, F>(finder: F)
    where
        F: FnOnce() -> Option<Arc<T>>,
        T: std::fmt::Display + Default + Clone, // 根据需要调整trait约束
    {
        let example = finder().unwrap();
        println!("{}", example);

        let mut data = example;
        println!("{}", data);

        if let Some(mut_ref) = Arc::get_mut(&mut data) {
            // 这里可以根据需要修改值
            // 由于泛型限制,我们可能需要传入修改逻辑
            println!("modified: {}", mut_ref);
        }
    }

    pub fn make_di_with_modifier<T, F, M>(finder: F, modifier: M)
    where
        F: FnOnce() -> Option<Arc<T>>,
        M: FnOnce(&mut T),
        T: std::fmt::Debug,
    {
        let example = finder().unwrap();
        println!("{:#?}", example);

        let mut data = example;
        println!("{:#?}", data);

        if let Some(mut_ref) = Arc::get_mut(&mut data) {
            modifier(mut_ref);
            println!("modified: {:#?}", mut_ref);
        }
    }
    #[test]
    fn test_03_make_di() {
        make_di_with_modifier(
            find_bean_di_example,
            |data| {
                data.lock().unwrap().id = 111;
            }, // 修改逻辑作为参数传入
        );
    }
    fn get_di_value<T, F>(finder: F) -> Result<Arc<T>, Box<dyn std::error::Error>>
    where
        F: FnOnce() -> Option<Arc<T>>,
        T: Display,
    {
        let example = finder().ok_or("Failed to find DI example")?;
        println!("original: {}", example);
        Ok(example)
    }


    #[test]
    fn test_07_make_di() {
        ru_log::info("/conf handler called");
        let c = find_bean_ru_config().unwrap().lock().unwrap().read_clone();
        //HttpResponse::Ok()
        // .json(c )

        let json_str = serde_json::to_string(&c.web).unwrap();
        ru_log::info2("conf response length:", json_str.len());
    }
}