Skip to content

结构体派生及可见性问题 #38

@ADP-P-P

Description

@ADP-P-P

暴露BusinessHandle

发送消息依赖于结构体BusinessHandle,但是该结构体位于core下,不方便解耦

type MessageSender = Arc<mania::core::business::BusinessHandle>;
                            //    ^___ module is private

下面是例子

// mod p1
struct A {}
     //^__声明为私有

pub fn get_a()->A{
    return  A{};
}
// mod p2
fn test(){
    let a_entity = get_a();
    func_with_a_param(a_entity);
}

fn func_with_a_param(a:A){}
                //    ^__ 无法传值

fn func_with_dyn(a:Box<dyn ATrait>){}

trait ATrait{}

impl ATrait for A {
    //         ^___ 无法通过封装结构体及实现特性的方式传值
}

GroupEvent实现Clone/Copy派生

处理消息同时执行协程代码时,由于GroupEvent底层被RwLockReadGuard保护,无法越过线程边界(await)进行上下文切换

同时,由于GroupEvent没有实现Clone/Copy派生,无法通过RwLockmpsc::channel发送

由于没有实现Clone/Copy派生,提升了代码的耦合度及降低了程序的灵活性

关于manim的一些建议

作为机器人短时间内处理消息有限,或许可以在牺牲一部分性能的情况下提升编码体验

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions