Skip to main content

Rust SDK

The official Rust SDK for RotaStellar, providing type-safe primitives for orbital compute and space intelligence applications.
Status: Early Access — Request API key
The Rust SDK currently provides types only. The HTTP client is coming in a future release. For full API access, use the Python SDK or Node.js SDK.

Installation

Add to your Cargo.toml:
[dependencies]
rotastellar = "0.1"
Or use cargo:
cargo add rotastellar

Quick Start

use rotastellar::types::{Position, Orbit, Satellite};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a position (e.g., Kennedy Space Center)
    let pos = Position::new(28.5729, -80.6490, 0.0)?;
    println!("Position: {}, {}", pos.latitude, pos.longitude);

    // Create an ISS-like orbit
    let orbit = Orbit::new(6778.0, 0.0001, 51.6, 100.0, 90.0, 0.0)?;
    println!("Orbital period: {:.1} minutes", orbit.orbital_period_minutes());
    println!("Apogee: {:.1} km, Perigee: {:.1} km", orbit.apogee_km(), orbit.perigee_km());

    Ok(())
}

Available Types

Position

Geographic position with altitude:
use rotastellar::types::Position;

// Create with validation
let pos = Position::new(28.5729, -80.6490, 408.0)?;

// Access fields
println!("Latitude: {}", pos.latitude);
println!("Longitude: {}", pos.longitude);
println!("Altitude: {} km", pos.altitude_km);
FieldTypeDescription
latitudef64Latitude in degrees (-90 to 90)
longitudef64Longitude in degrees (-180 to 180)
altitude_kmf64Altitude above sea level in km

Orbit

Keplerian orbital elements:
use rotastellar::types::Orbit;

// Create an orbit (ISS-like)
let orbit = Orbit::new(
    6778.0,   // semi_major_axis_km
    0.0001,   // eccentricity
    51.6,     // inclination_deg
    100.0,    // raan_deg
    90.0,     // arg_periapsis_deg
    0.0       // true_anomaly_deg
)?;

// Computed properties
println!("Period: {:.1} minutes", orbit.orbital_period_minutes());
println!("Apogee: {:.1} km", orbit.apogee_km());
println!("Perigee: {:.1} km", orbit.perigee_km());
println!("Mean motion: {:.2} rev/day", orbit.mean_motion());
FieldTypeDescription
semi_major_axis_kmf64Semi-major axis in km
eccentricityf64Orbital eccentricity (0-1)
inclination_degf64Inclination in degrees (0-180)
raan_degf64Right ascension of ascending node
arg_periapsis_degf64Argument of periapsis
true_anomaly_degf64True anomaly

Satellite

Satellite information with optional orbit and position:
use rotastellar::types::{Satellite, Position, Orbit};

let sat = Satellite::new("sat_123", 25544, "ISS")
    .with_operator("NASA/Roscosmos")
    .with_constellation("Space Station")
    .with_position(Position::new(28.5729, -80.6490, 408.0)?)
    .with_orbit(orbit);

println!("Name: {}", sat.name);
println!("NORAD ID: {}", sat.norad_id);
if let Some(pos) = &sat.position {
    println!("At: {}, {}", pos.latitude, pos.longitude);
}

TimeRange

Time range for queries:
use rotastellar::types::TimeRange;

// Create a 24-hour time range starting now
let range = TimeRange::next_hours(24.0);
println!("Start: {}", range.start);
println!("End: {}", range.end);

Configuration

The SDK provides configuration utilities for when the HTTP client is available:
use rotastellar::{Config, ConfigBuilder};

let config = Config::default();
println!("Base URL: {}", config.base_url);
println!("Timeout: {:?}", config.timeout);

Authentication Utilities

Validate and mask API keys:
use rotastellar::{validate_api_key, mask_api_key, Environment};

// Validate an API key
match validate_api_key(Some("rs_live_abc123")) {
    Ok(env) => println!("Valid key for {:?} environment", env),
    Err(e) => println!("Invalid: {}", e),
}

// Mask a key for logging
let masked = mask_api_key("rs_live_abc123def456");
println!("Masked: {}", masked);  // rs_live_abc...

Error Handling

use rotastellar::error::{RotaStellarError, ValidationError};
use rotastellar::types::Position;

fn create_position() -> Result<Position, RotaStellarError> {
    // This will fail validation (latitude > 90)
    let pos = Position::new(91.0, 0.0, 0.0)?;
    Ok(pos)
}

match create_position() {
    Ok(pos) => println!("Created: {:?}", pos),
    Err(RotaStellarError::Validation(e)) => {
        println!("Validation error on '{}': {}", e.field, e.message);
    }
    Err(e) => println!("Error: {}", e),
}

Error Types

ErrorDescription
RotaStellarError::ValidationInput validation failed
RotaStellarError::AuthenticationAPI key issues
RotaStellarError::ApiAPI returned an error
RotaStellarError::NetworkNetwork connectivity issues

Constants

use rotastellar::{EARTH_RADIUS_KM, EARTH_MU};

println!("Earth radius: {} km", EARTH_RADIUS_KM);  // 6378.137
println!("Earth GM: {} km³/s²", EARTH_MU);         // 398600.4418

Serde Support

All types implement Serialize and Deserialize:
use rotastellar::types::Position;
use serde_json;

let pos = Position::new(28.5729, -80.6490, 408.0)?;

// Serialize
let json = serde_json::to_string(&pos)?;
println!("{}", json);

// Deserialize
let parsed: Position = serde_json::from_str(&json)?;

Coming Soon

The following features are planned for future releases:
  • HTTP Client — Full API client with async support
  • Blocking Client — Synchronous API for non-async contexts
  • Streaming — Real-time satellite position updates
  • TLE Parsing — Two-line element set parsing and propagation

Source Code