Skip to main content

devela/run/
permission.rs

1// devela/src/run/permission.rs
2//
3//! Defines [`PermissionState`], [`PermissionError`].
4//
5
6use crate::AsyncPoll;
7
8#[doc = crate::_tags!(error runtime)]
9/// An error while determining or changing a permission state.
10#[doc = crate::_doc_meta!{
11    location("run/permission", enum PermissionError),
12    test_size_of(PermissionError = 1|8; niche Option),
13}]
14#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
15pub enum PermissionError {
16    /// The permission or requested permission operation is unsupported.
17    Unsupported,
18
19    /// The permission operation could not be completed.
20    Failed,
21}
22crate::impl_trait![fmt::Display+Error for PermissionError |self, f| match *self {
23    Self::Unsupported => f.write_str(""),
24    Self::Failed => f.write_str(""),
25}];
26
27#[doc = crate::_tags!(runtime result)]
28/// The result of polling a non-blocking permission query.
29#[doc = crate::_doc_meta!{
30    location("run/permission", type PermissionQuery),
31    test_size_of(PermissionQuery = 2|16; niche Option),
32}]
33/// - [`Pending`][AsyncPoll::Pending] means that no result is available yet.
34/// - [`Ready(Ok(_))`][AsyncPoll::Ready] contains the current permission state.
35/// - [`Ready(Err(_))`][AsyncPoll::Ready] means the state could not be determined.
36pub type PermissionQuery<E = PermissionError> = AsyncPoll<Result<PermissionState, E>>;
37
38#[doc = crate::_tags!(runtime state)]
39/// The effective authorization state of a permission.
40#[doc = crate::_doc_meta!{
41    location("run/permission", enum PermissionState),
42    test_size_of(PermissionState = 1|8; niche Option),
43}]
44#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
45pub enum PermissionState {
46    /// The protected operation is currently authorized.
47    Granted,
48
49    /// Authorization remains undecided or requestable.
50    ///
51    /// Requesting the permission may require interaction with the user,
52    /// a policy provider, or another authorizing authority.
53    Prompt,
54
55    /// The protected operation is currently not authorized.
56    Denied,
57}
58crate::_impl_init![Self::Prompt => PermissionState];