nazar

Crates.ionazar
lib.rsnazar
version1.0.7
sourcesrc
created_at2017-07-19 10:09:36.420136
updated_at2017-08-08 06:41:41.211383
descriptionA Tile38 client in rust!
homepagehttps://github.com/younisshah/nazar
repository
max_upload_size
id24069
size13,955
Younis Shah (younisshah)

documentation

https://github.com/younisshah/nazar

README

Nazar

nazar

Tile38 is an open source (MIT licensed), in-memory geolocation data store, spatial index, and realtime geofence. It supports a variety of object types including lat/lon points, bounding boxes, XYZ tiles, Geohashes, and GeoJSON.

nazar is a Tile38 client in rust!

The API is a bit sane now albeit still weird and unstable.

API will change a lot

Install

In your Cargo.toml file add under [dependencies] section

[dependencies]
nazar = "1.0.7"

Usage

  1. SET command
use self::nazar::t38::Types::{String, Float};
let n = nazar::t38::Client::from("redis://127.0.0.1:9851");

match n.execute("SET", vec![String("my"), String("home"), Float(23.12), Float(45.343)]) {
    Ok(s) => println!("{}", s),
    Err(e) => panic!(e)
}

  1. GET command
use self::nazar::t38::Types::{String};
let n = nazar::t38::Client::from("redis://127.0.0.1:9851");

match n.execute("GET", vec![String("my"), String("home")]) {
    Ok(s) => println!("{}", s),
    Err(e) => panic!(e)
}
  1. New API to execute T38 command - cmd, arg and execute_with_args. This is a high-level API to execute Tile38 commands!
let mut n = nazar::t38::Client::from("redis://127.0.0.1:9851");
n.cmd("SET").arg("drivers").arg("qwerty").arg("POINT").arg("23.54").arg("32.74");
match n.execute_with_args() {
    Ok(r) => println!("Result {}", r),
    Err(e) => panic!(e),
};
  1. PING to check if the server is live or dead.
use nazar::t38::{Client};
let is_live = Client::ping("redis://127.0.0.1:9851");

Geofence features

To open a fence only, it is advisable to use new associated method like this:

let n = nazar::t38::Client::new();

Then use n to open a geofence like this:

  1. Open a static FENCE using open_fence:
let work = |msg| {
    println!("FENCE updates {:?}", msg);
};
n.open_fence("ws://127.0.0.1:9851", "my_fleet", "12.12", "33.22", "6000", work);
  1. Open a static geofence with GeoJSON object type. open_fence_within
let work = |msg| {
   println!("FENCE updates {:?}", msg);
};
n.open_fence_within("ws://localhost:9851", "my_fleet", "qwerty123", vec![vec![12.32, 23.4], vec![22.32, 33.4], vec![42.32, 23.5], vec![12.32, 23.4]], work)
  1. Open a static FENCE using open_fence (use this when to want to communicate with the server as well):
fn action (out: &nazar::t38::NazarSender, msg: String) {
    out.send("OK").unwrap();
    println!("{}", msg);
    // do stuff with msg
}

//.....

n.open_fence2("ws://127.0.0.1:9851", "my_fleet", "12.12", "33.22", "6000", action);
  1. Open a static geofence with GeoJSON object type. open_fence_within (use this when you want to communicate with the server as well):
fn action (out: &nazar::t38::NazarSender, msg: String) {
   out.send("OK").unwrap();
   println!("{}", msg);
   // do stuff with msg
}

//.....

n.open_fence_within2("ws://localhost:9851", "my_fleet", "qwerty123", vec![vec![12.32, 23.4], vec![22.32, 33.4], vec![42.32, 23.5], vec![12.32, 23.4]], action);
  1. Open a static geofence (circular) using open_fence_and_send (use this when you want to send updates to the client who opened the fence)
 n.open_fence_and_send("ws://127.0.0.1:9851", "my_fleet", "12.12", "33.22", "6000", client); // client is a NazarSender
  1. Open a static geofence (polygonal) using open_fence_within_and_send (use this when you want to send updates to the client who opened the fence)
 n.open_fence_within_and_send("ws://localhost:9851", "my_fleet", "qwerty123", vec![vec![12.32, 23.4], vec![22.32, 33.4], vec![42.32, 23.5], vec![12.32, 23.4]], client); // client is a NazarSender

A work in progress

TODO

  1. Make sane API.
  2. Documentation
  3. Roaming FENCE
Commit count: 0

cargo fmt