#cat #ffi

cat-rs

cat client with rust

14 releases

0.1.0-alpha.0 Nov 10, 2019
0.0.9 Oct 11, 2019
0.0.8-alpha.2 Jul 29, 2019
0.0.8-alpha.1 Apr 26, 2019
0.0.2 Mar 11, 2019

#8 in #cat

Download history 2/week @ 2021-04-01 17/week @ 2021-04-08 41/week @ 2021-04-15 2/week @ 2021-04-22 2/week @ 2021-04-29 15/week @ 2021-05-13 15/week @ 2021-06-10 5/week @ 2021-07-01 1/week @ 2021-07-08 31/week @ 2021-07-15

57 downloads per month

MIT license

355KB
8K SLoC

C 7.5K SLoC // 0.1% comments Rust 285 SLoC // 0.0% comments

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

extern crate cat_rs as cat;
use cat::logEvent;
use cat::CatClient;
use cat::CatTransaction;

let mut cat = CatClient::new("test");
cat.init()?
let mut tr = CatTransaction::new("foo", "bar")

tr.log("test", "it", "0", "");
tr.complete();

Ok(())

work with neon

  1. cat transaction exported to nodejs.

cat.rs:

use cat_rs::{self, CatTransaction};
use neon::prelude::*;

declare_types! {
    pub class JsCatTransaction for CatTransaction {
        init(mut ctx) {
            let _type = ctx.argument::<JsString>(0)?.value();
            let _name = ctx.argument::<JsString>(1)?.value();
            let trans = CatTransaction::new(_type, _name);
            Ok(trans)
        }

        method complete(mut ctx) {
            let mut this = ctx.this();
            let guard = ctx.lock();
            {
                let mut trans  = this.borrow_mut(&guard);
                trans.complete();
            }
            Ok(ctx.undefined().upcast())
        }

        method log(mut ctx) {
            let _type = ctx.argument::<JsString>(0)?.value();
            let _name = ctx.argument::<JsString>(0)?.value();
            let _stat = ctx.argument::<JsString>(0)?.value();
            let _data = ctx.argument::<JsString>(0)?.value();

            {
                let mut this = ctx.this();
                let guard = ctx.lock();
                let mut trans = this.borrow_mut(&guard);

                trans.log(_type, _name, _stat, _data);
            }

            Ok(ctx.undefined().upcast())
        }
    }
}
  1. register this class

lib.rs

use cat::JsCatTransaction;

register_module!(mut ctx, {
    ctx.export_class::<JsCatTransaction>("NodeCatTransaction")?;
})

Dependencies

~1–3.5MB
~82K SLoC