#![allow(clippy::result_unit_err)]
mod error;
mod sys;
pub use error::{Error, Result};
pub struct Uri<'a, 'b> {
inner: sys::Uri<'a, 'b>,
}
impl<'a, 'b> Uri<'a, 'b> {
pub fn new(s: &'a str) -> Self {
Self {
inner: sys::Uri::new(s),
}
}
pub fn action(self, action: &'b str) -> Self {
Self {
inner: self.inner.action(action),
}
}
pub fn open(self) -> Result<()> {
self.open_with_completion(|_success| {
#[cfg(feature = "log")]
log::debug!("Uri::open(): called on_completion closure, success: {}", _success);
})
}
pub fn open_with_completion<F>(self, on_completion: F) -> Result<()>
where
F: Fn(bool) + Send + 'static,
{
if self.inner.is_empty() {
#[cfg(feature = "log")]
log::error!("Error: cannot open an empty URI.");
return Err(Error::MalformedUri);
}
self.inner.open(on_completion)
}
}