Trait cogs::cogs::Cog [] [src]

pub trait Cog: Into<Request> {
    type Output: Future<Item = Self::Item, Error = Self::Error> + From<Result<Response, Error>> + 'static;
    type Item: 'static;
    type Error: 'static;
}

Trait representing something that can be turned into a Cognitive Service endpoint.

In essence, it is capable of of

  1. Transforming from your data structure to a hyper::Request
  2. Transforming from a Result -> Future

Examples

let mut core = tokio_core::reactor::Core::new().unwrap();
let handle = core.handle();
let client = hyper::Client::configure()
    .connector(hyper_tls::HttpsConnector::new(4, &handle).unwrap())
    .keep_alive(true)
    .build(&handle);
let credentials = Credentials::new(sub_key);
let engine = Engine::new(credentials, client);
let translate_req = TranslateRequest {
    text: "Hello",
    from: Some("en"),
    to: "de",
    content_type: None,
    category: None,
};
let work = engine.run(translate_req);
// TODO: get a sandbox key so this actually works as expected, returning "Hallo"
assert_eq!(core.run(work).unwrap(), "")

Associated Types

What this Cog returns using input from the Engine

In short it needs be able to convert input from the Engine of the form Result> into something that implements Future.

It must also be "static", meaning that it doesn't refer to data that lives on the stack

Item type

Error type

Implementors