Skip to content

Conversation

@nerfZael
Copy link
Contributor

@nerfZael nerfZael commented May 17, 2023

The Client trait is now defined as follows:

pub trait Client: Invoker + WrapLoader + WrapInvoker + UriResolverHandler {}

The idea being that developers can now define type constraints based only on the traits that they need.
E.g.

  • if all function needs is the ability to invoke a URI then it only needs an invoker.
  • if it needs to be able to load and invoke wrappers then it needs a WrapLoader + WrapInvoker

The component traits of the Client are defined as follows:

pub trait Invoker: Send + Sync {
    fn invoke_raw(
        &self,
        uri: &Uri,
        method: &str,
        args: Option<&[u8]>,
        env: Option<&Env>,
        resolution_context: Option<&mut UriResolutionContext>,
    ) -> Result<Vec<u8>, Error>;
    fn get_implementations(&self, uri: &Uri) -> Result<Vec<Uri>, Error>;
    fn get_interfaces(&self) -> Option<InterfaceImplementations>;
    fn get_env_by_uri(&self, uri: &Uri) -> Option<&Env>;
}
pub trait WrapLoader: Send + Sync {
  fn load_wrapper(
      &self,
      uri: &Uri,
      resolution_context: Option<&mut UriResolutionContext>,
  ) -> Result<Arc<dyn Wrapper>, Error>;
}
pub trait WrapInvoker: Send + Sync {
  fn invoke_wrapper_raw(
      &self,
      wrapper: &dyn Wrapper,
      uri: &Uri,
      method: &str,
      args: Option<&[u8]>,
      env: Option<&Env>,
      resolution_context: Option<&mut UriResolutionContext>,
  ) -> Result<Vec<u8>, Error>;
}
pub trait UriResolverHandler {
  fn try_resolve_uri(
      &self,
      uri: &Uri,
      resolution_context: Option<&mut UriResolutionContext>,
  ) -> Result<UriPackageOrWrapper, Error>;
}

Additionally, get_env_by_uri has been moved from the Client trait into the Invoker trait. It makes sense that anyone with access to invoker can also get env's just like interfaces and implementations. This is especially true in the full version of WRAP 0.2 where getting those 3 is only possible through invocations.

@nerfZael nerfZael marked this pull request as ready for review May 17, 2023 15:55
@nerfZael nerfZael requested review from cbrzn and namesty and removed request for namesty May 17, 2023 15:55
@namesty namesty merged commit c46823c into nerfzael-wrapper-uri-and-abort-handler May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants