SetOptions

Struct SetOptions 

Source
pub struct SetOptions {
    pub timestamp: Option<SystemTime>,
}
Expand description

Options for setting values.

Fields§

§timestamp: Option<SystemTime>

Optional timestamp for the update (defaults to now if None)

Implementations§

Source§

impl SetOptions

Source

pub fn with_timestamp(timestamp: SystemTime) -> SetOptions

Examples found in repository?
examples/getting_started.rs (line 115)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    // Initialize logging (set RUST_LOG=debug to see detailed logs)
7    env_logger::init();
8
9    println!("=== Spatio - Getting Started ===\n");
10
11    // Create an in-memory database
12    let db = Spatio::memory()?;
13    println!("✓ Created in-memory database\n");
14
15    // === SPATIAL OPERATIONS ===
16    println!("1. Spatial Point Storage (Hot State)");
17    println!("------------------------------------");
18
19    // Store geographic points
20    let nyc = Point3d::new(-74.0060, 40.7128, 0.0);
21    let london = Point3d::new(-0.1278, 51.5074, 0.0);
22    let paris = Point3d::new(2.3522, 48.8566, 0.0);
23
24    db.upsert(
25        "cities",
26        "nyc",
27        nyc.clone(),
28        serde_json::json!({"data": "New York"}),
29        None,
30    )?;
31    println!("   Stored nyc at ({}, {})", nyc.x(), nyc.y());
32
33    db.upsert(
34        "cities",
35        "london",
36        london.clone(),
37        serde_json::json!({"data": "London"}),
38        None,
39    )?;
40    println!("   Stored london at ({}, {})", london.x(), london.y());
41
42    db.upsert(
43        "cities",
44        "paris",
45        paris.clone(),
46        serde_json::json!({"data": "Paris"}),
47        None,
48    )?;
49    println!("   Stored paris at ({}, {})", paris.x(), paris.y());
50    println!("   Stored 3 cities with automatic spatial indexing");
51
52    // Find nearby cities within radius (in meters)
53    // using query_radius which now returns distance
54    let nearby = db.query_radius("cities", &london, 500_000.0, 10)?;
55    println!("   Found {} cities within 500km of London:", nearby.len());
56    for (loc, dist) in &nearby {
57        println!(
58            "     - {} ({:.1}m away): {:?}",
59            loc.object_id, dist, loc.metadata
60        );
61    }
62    println!();
63
64    // === TRAJECTORY TRACKING ===
65    println!("2. Trajectory Tracking (Cold State)");
66    println!("-----------------------------------");
67
68    let vehicle_path = vec![
69        TemporalPoint {
70            point: Point::new(-74.0060, 40.7128),
71            timestamp: UNIX_EPOCH + Duration::from_secs(1640995200),
72        },
73        TemporalPoint {
74            point: Point::new(-74.0040, 40.7150),
75            timestamp: UNIX_EPOCH + Duration::from_secs(1640995260),
76        },
77        TemporalPoint {
78            point: Point::new(-74.0020, 40.7172),
79            timestamp: UNIX_EPOCH + Duration::from_secs(1640995320),
80        },
81    ];
82
83    db.insert_trajectory("logistics", "vehicle:truck001", &vehicle_path)?;
84    println!(
85        "   Stored vehicle trajectory with {} waypoints",
86        vehicle_path.len()
87    );
88
89    // Query trajectory for time range
90    let path_segment = db.query_trajectory(
91        "logistics",
92        "vehicle:truck001",
93        UNIX_EPOCH + Duration::from_secs(1640995200),
94        UNIX_EPOCH + Duration::from_secs(1640995320),
95        100,
96    )?;
97    println!(
98        "   Retrieved {} waypoints from trajectory\n",
99        path_segment.len()
100    );
101
102    // === HISTORICAL INGESTION ===
103    println!("3. Historical Data Ingestion");
104    println!("----------------------------");
105
106    // Insert a point with a specific timestamp in the past
107    let past_time = SystemTime::now() - Duration::from_secs(3600);
108    let past_pos = Point3d::new(10.0, 10.0, 0.0);
109
110    db.upsert(
111        "fleet",
112        "old_truck",
113        past_pos,
114        serde_json::json!({"data": "Historical Data"}),
115        Some(spatio::SetOptions::with_timestamp(past_time)),
116    )?;
117    println!("   Ingested historical data point\n");
118
119    // === DATABASE STATS ===
120    println!("4. Database Statistics");
121    println!("----------------------");
122
123    let stats = db.stats();
124    println!("   Stats available: {:?}", stats);
125
126    println!("=== Getting Started Complete! ===");
127    println!("\nKey Features Demonstrated:");
128    println!("  • Real-time location updates (Hot State)");
129    println!("  • Spatial radius queries");
130    println!("  • Trajectory tracking (Cold State)");
131    println!("  • Historical data ingestion");
132
133    Ok(())
134}

Trait Implementations§

Source§

impl Clone for SetOptions

Source§

fn clone(&self) -> SetOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SetOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for SetOptions

Source§

fn default() -> SetOptions

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SetOptions

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<SetOptions, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SetOptions

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,