fractal/utils/location/
mod.rs1use futures_util::Stream;
4use geo_uri::GeoUri;
5
6#[cfg(target_os = "linux")]
7mod linux;
8
9cfg_if::cfg_if! {
10 if #[cfg(target_os = "linux")] {
11 pub(crate) type Location = linux::LinuxLocation;
13 } else {
14 pub(crate) type Location = unimplemented::UnimplementedLocation;
16 }
17}
18
19pub(crate) trait LocationExt {
21 fn is_available(&self) -> bool;
23
24 async fn init(&self) -> Result<(), LocationError>;
26
27 async fn updates_stream(&self) -> Result<impl Stream<Item = GeoUri> + '_, LocationError>;
29}
30
31#[cfg(not(target_os = "linux"))]
33mod unimplemented {
34 use super::*;
35
36 #[derive(Debug)]
37 pub(crate) struct UnimplementedLocation;
38
39 impl LocationExt for UnimplementedLocation {
40 fn is_available(&self) -> bool {
42 false
43 }
44
45 async fn init(&self) -> Result<(), LocationError> {
47 unimplemented!()
48 }
49
50 async fn updates_stream(&self) -> Result<impl Stream<Item = GeoUri> + '_, LocationError> {
52 unimplemented!()
53 }
54 }
55}
56
57#[derive(Debug, Clone, Copy)]
59pub(crate) enum LocationError {
60 Cancelled,
62 Disabled,
64 Other,
66}