Crate spaceapi[−][src]
Expand description
SpaceAPI definitions and serialization.
This crate contains all data-related definitions that are present in the
SpaceAPI. It also handles serializing and
deserializing of that data from/to JSON by implementing the Serde
Serialize
and
Deserialize
traits for all structs.
The currently supported SpaceAPI version is 0.13. It is not yet fully implemented.
If you want to implement a SpaceAPI server on top of these types, you
might want to take a look at the spaceapi_server
crate.
This library requires Rust 1.20.0 or newer.
Examples
Serializing
You can create a new Status
instance by using the StatusBuilder
.
use serde_json; use spaceapi::{State, Status, StatusBuilder, Location, Contact, IssueReportChannel}; let status = StatusBuilder::new("coredump") .logo("https://www.coredump.ch/logo.png") .url("https://www.coredump.ch/") .state(State{ open: Some(false), ..State::default() }) .location( Location { address: None, lat: 47.22936, lon: 8.82949, }) .contact( Contact { irc: Some("irc://freenode.net/#coredump".into()), twitter: Some("@coredump_ch".into()), foursquare: Some("525c20e5498e875d8231b1e5".into()), email: Some("danilo@coredump.ch".into()), ..Default::default() }) .add_issue_report_channel(IssueReportChannel::Email) .add_issue_report_channel(IssueReportChannel::Twitter) .build() .expect("Creating status failed"); let serialized = serde_json::to_string(&status).unwrap(); let deserialized: Status = serde_json::from_str(&serialized).unwrap();
Deserializing
You can deserialize any struct of the SpaceAPI through Serde:
use serde_json; use spaceapi::Location; let location = "{\"lat\": 47.22936, \"lon\": 8.82949}"; let decoded: Location = serde_json::from_str(location).unwrap(); println!("{:?}", decoded); // Output: // Location { address: None, lat: 47.22936000000001, lon: 8.829490000000002 }
Re-exports
pub use crate::sensors::PeopleNowPresentSensor;
pub use crate::sensors::SensorTemplate;
pub use crate::sensors::Sensors;
pub use crate::sensors::TemperatureSensor;
Modules
Module defining all sensor related structures.
Structs
The main SpaceAPI status object.
Builder for the Status
object.
Enums
Functions
Return own crate version. Used in API responses.