mod error;
mod sys;
use std::time::SystemTime;
pub use crate::error::{Error, Result};
pub struct Manager {
inner: sys::Manager,
}
impl Manager {
pub fn new<T>(handler: T) -> Result<Self>
where
T: Handler,
{
Ok(Manager {
inner: sys::Manager::new(handler)?,
})
}
#[cfg(target_os = "linux")]
pub fn new_with_desktop_id<T>(handler: T, desktop_id: &str) -> Result<Self>
where
T: Handler,
{
Ok(Manager {
inner: sys::Manager::new_with_desktop_id(handler, desktop_id)?,
})
}
#[cfg(not(target_os = "linux"))]
pub fn new_with_desktop_id<T>(handler: T, _desktop_id: &str) -> Result<Self>
where
T: Handler,
{
Self::new(handler)
}
pub fn request_authorization(&self, access: Access, accuracy: Accuracy) -> Result<()> {
self.inner.request_authorization(access, accuracy)
}
pub fn update_once(&self) -> Result<()> {
self.inner.update_once()
}
pub fn start_updates(&mut self) -> Result<()> {
self.inner.start_updates()
}
pub fn stop_updates(&mut self) -> Result<()> {
self.inner.stop_updates()
}
}
pub trait Handler: 'static + Send + Sync {
fn handle(&self, location: Location<'_>);
fn error(&self, error: Error);
}
pub struct Location<'a> {
inner: sys::Location<'a>,
}
impl Location<'_> {
pub fn coordinates(&self) -> Result<Coordinates> {
self.inner.coordinates()
}
pub fn altitude(&self) -> Result<f64> {
self.inner.altitude()
}
pub fn bearing(&self) -> Result<f64> {
self.inner.bearing()
}
pub fn speed(&self) -> Result<f64> {
self.inner.speed()
}
pub fn time(&self) -> Result<SystemTime> {
self.inner.time()
}
}
#[derive(Copy, Clone, Debug)]
pub struct Coordinates {
pub latitude: f64,
pub longitude: f64,
}
#[derive(Copy, Clone, Debug)]
pub enum Access {
Foreground,
Background,
}
#[derive(Copy, Clone, Debug)]
pub enum Accuracy {
Approximate,
Precise,
}