项目作者: uuhan

项目描述 :
Rust Crate for [cat](https://github.com/dianping/cat)
高级语言: C
项目地址: git://github.com/uuhan/cat-rs.git
创建时间: 2019-01-30T05:53:44Z
项目社区:https://github.com/uuhan/cat-rs

开源协议:

下载


cat Build Status crates.io

Rust cat binding.

NB: This crate is mostly created for Nodejs’s Native Addons(using neon) currently.

Examples

create a new cat client

  1. extern crate cat_rs as cat;
  2. use cat::logEvent;
  3. use cat::CatClient;
  4. use cat::CatTransaction;
  5. let mut cat = CatClient::new("test");
  6. cat.init()?
  7. let mut tr = CatTransaction::new("foo", "bar")
  8. tr.log("test", "it", "0", "");
  9. tr.complete();
  10. Ok(())

work with neon

  1. cat transaction exported to nodejs.

cat.rs:

  1. use cat_rs::{self, CatTransaction};
  2. use neon::prelude::*;
  3. declare_types! {
  4. pub class JsCatTransaction for CatTransaction {
  5. init(mut ctx) {
  6. let _type = ctx.argument::<JsString>(0)?.value();
  7. let _name = ctx.argument::<JsString>(1)?.value();
  8. let trans = CatTransaction::new(_type, _name);
  9. Ok(trans)
  10. }
  11. method complete(mut ctx) {
  12. let mut this = ctx.this();
  13. let guard = ctx.lock();
  14. {
  15. let mut trans = this.borrow_mut(&guard);
  16. trans.complete();
  17. }
  18. Ok(ctx.undefined().upcast())
  19. }
  20. method log(mut ctx) {
  21. let _type = ctx.argument::<JsString>(0)?.value();
  22. let _name = ctx.argument::<JsString>(0)?.value();
  23. let _stat = ctx.argument::<JsString>(0)?.value();
  24. let _data = ctx.argument::<JsString>(0)?.value();
  25. {
  26. let mut this = ctx.this();
  27. let guard = ctx.lock();
  28. let mut trans = this.borrow_mut(&guard);
  29. trans.log(_type, _name, _stat, _data);
  30. }
  31. Ok(ctx.undefined().upcast())
  32. }
  33. }
  34. }
  1. register this class

lib.rs

  1. use cat::JsCatTransaction;
  2. register_module!(mut ctx, {
  3. ctx.export_class::<JsCatTransaction>("NodeCatTransaction")?;
  4. })