yyu-nim / poseidonos-rtype

poseidonos in rust for fun!
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

Callback에 임의의 함수&파라미터 전달할 수 있도록 디자인 #12

Open yyu-nim opened 2 years ago

yyu-nim commented 2 years ago

https://github.com/yyu-nim/poseidonos-rtype/pull/11

몇가지 안을 비교해보고, 한가지 구현해 볼 것.

  1. Callback 파라미터 & 리턴을 enum 타입으로 묶어서 처리

    enum CallbackParam {
    CallbackParam1(~, ~, ~),
    CallbackParam2(~, ~), 
    ...
    }
    enum CallbackResponse {
    CallbackResponse1(~, ~, ~, ~),
    CallbackResponse2(~), 
    ...
    }
    trait Callback {
    fn Execute(&self, param: CallbackParam) -> CallbackResponse;
    }
  2. Trait의 associated type 으로 처리

    trait Callback {
    type CallbackParam;
    type CallbackResponse;
    fn Execute(&self, param: Self::CallbackParam) -> Self::CallbackResponse;
    }
  3. Any 타입 활용해서 upcasting & downcasting 하기

    trait Callback {
    fn Execute(&self, param: Any) -> Any;
    }