Crates.io | nazar |
lib.rs | nazar |
version | 1.0.7 |
source | src |
created_at | 2017-07-19 10:09:36.420136 |
updated_at | 2017-08-08 06:41:41.211383 |
description | A Tile38 client in rust! |
homepage | https://github.com/younisshah/nazar |
repository | |
max_upload_size | |
id | 24069 |
size | 13,955 |
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
In your Cargo.toml
file add under [dependencies]
section
[dependencies]
nazar = "1.0.7"
SET
commanduse 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)
}
GET
commanduse 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)
}
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),
};
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");
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:
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);
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)
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);
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);
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
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
TODO
FENCE