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
impl SetOptions
Sourcepub fn with_timestamp(timestamp: SystemTime) -> SetOptions
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
impl Clone for SetOptions
Source§fn clone(&self) -> SetOptions
fn clone(&self) -> SetOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SetOptions
impl Debug for SetOptions
Source§impl Default for SetOptions
impl Default for SetOptions
Source§fn default() -> SetOptions
fn default() -> SetOptions
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for SetOptions
impl<'de> Deserialize<'de> for SetOptions
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<SetOptions, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
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
impl Serialize for SetOptions
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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§
impl Freeze for SetOptions
impl RefUnwindSafe for SetOptions
impl Send for SetOptions
impl Sync for SetOptions
impl Unpin for SetOptions
impl UnwindSafe for SetOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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