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.



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")
        open: Some(false),
        Location {
            address: None,
            lat: 47.22936,
            lon: 8.82949,
        Contact {
            irc: Some("irc://".into()),
            twitter: Some("@coredump_ch".into()),
            foursquare: Some("525c20e5498e875d8231b1e5".into()),
            email: Some("".into()),
    .expect("Creating status failed");
let serialized = serde_json::to_string(&status).unwrap();
let deserialized: Status = serde_json::from_str(&serialized).unwrap();


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 }


pub use crate::sensors::PeopleNowPresentSensor;
pub use crate::sensors::SensorTemplate;
pub use crate::sensors::Sensors;
pub use crate::sensors::TemperatureSensor;


Module defining all sensor related structures.




Return own crate version. Used in API responses.