Expand description
§Overview
This crate provides functions which can query a SkySpark server, using
the Haystack REST API and the SkySpark REST API’s eval
operation.
Some Haystack operations are not implemented
(watch* operations, pointWrite and invokeAction).
§Example Usage
Put this in the main function in the main.rs
file to create
and use a SkySparkClient
:
use raystack::{SkySparkClient, ValueExt};
use url::Url;
let url = Url::parse("https://www.example.com/api/projName/").unwrap();
let mut client = SkySparkClient::new(url, "username", "p4ssw0rd").await.unwrap();
let sites_grid = client.eval("readAll(site)").await.unwrap();
// Print the raw JSON:
println!("{}", sites_grid.to_json_string_pretty());
// Working with the Grid struct:
println!("All columns: {:?}", sites_grid.cols());
println!("first site id: {:?}", sites_grid.rows()[0]["id"].as_hs_ref().unwrap());
See the examples
folder for more usage examples.
The Grid struct is a wrapper around the underlying JSON Value enum
provided by the serde_json
crate. See the
documentation for Value
for more information on how to query for data stored within it.
Additional functions for extracting Haystack values from the underlying
JSON are found in this crate’s ValueExt
trait.
Modules§
Structs§
- Basic
Number - A Haystack Number, encapsulating a scalar value and an optional unit value. The unit is represented as a string. This does not represent Haystack scientific notation numbers.
- Coord
- A Haystack Coord, representing a geographical coordinate.
- Date
- A Haystack Date with no time zone.
- Date
Time - A Haystack DateTime.
- From
Hayson Error - Grid
- A wrapper around a
serde_json::Value
which represents a Haystack Grid. Columns will always be sorted in alphabetical order. - Marker
- A Haystack marker.
- Na
- A Haystack NA (not available).
- Parse
Json Grid Error - Error denoting that a JSON value could not be parsed into a
Grid
. - Parse
RefError - An error indicating that a
Ref
could not be parsed. - Parse
TagName Error - An error indicating that a
TagName
could not be parsed. - Ref
- A Haystack Ref.
- Remove
Marker - A Haystack remove marker.
- Scientific
Number - A Haystack scientific notation Number, encapsulating a value and an optional unit value. The unit is represented as a string.
- SkySpark
Client - A client for interacting with a SkySpark server.
- Symbol
- A Haystack Symbol.
- TagName
- A Haystack tag name.
- Time
- A Haystack Time with no time zone.
- Uri
- A Haystack Uri.
- Xstr
- A Haystack XStr.
Enums§
- Error
- Describes the kinds of errors that can occur in this crate.
- HisRead
Range - Represents the different time range queries that can be sent
as part of the
hisRead
Haystack operation. - NewSky
Spark Client Error - Errors that can occur when creating a new
SkySparkClient
. - Number
- A Haystack number.
Traits§
- Hayson
- Something which can be converted to and from Hayson (the new JSON encoding used by Project Haystack).
- Value
Ext - An extension trait for the
serde_json::Value
enum, containing helper functions which make it easier to parse specific Haystack types from the underlying Hayson encoding (a JSON value in a specific format, see https://github.com/j2inn/hayson).
Functions§
- is_
tag_ name - Return true if the string is a valid tag name.
- skyspark_
tz_ string_ to_ tz - Converts a string containing a SkySpark time zone name into the matching
Tz
variant from the chrono_tz crate.