Skip to main content

PermissionRequest

Struct PermissionRequest 

Source
pub struct PermissionRequest {
    pub capability: Capability,
    pub scope: Scope,
    pub reason: String,
    pub ttl: Option<Duration>,
}

Fields§

§capability: Capability§scope: Scope§reason: String§ttl: Option<Duration>

Implementations§

Source§

impl PermissionRequest

Source

pub fn new( capability: Capability, scope: Scope, reason: impl Into<String>, ) -> Self

Examples found in repository?
examples/assistant_context_adapter.rs (lines 151-155)
150fn grant_clipboard_content(api: &mut ContextApi) -> Result<(), Box<dyn std::error::Error>> {
151    api.request_permission(PermissionRequest::new(
152        Capability::ReadClipboardContent,
153        Scope::Session,
154        "Enable content-level context in assistant adapter demo",
155    ))?;
156    println!("clipboard content access granted for current session");
157    Ok(())
158}
More examples
Hide additional examples
examples/clipboard_monitor.rs (lines 20-24)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut api = ContextApi::new()?;
7
8    api.subscribe(SignalType::Clipboard, |signal| {
9        println!(
10            "clipboard changed: type={:?}, bytes={}, source={}, sensitive={}, command={}",
11            signal.content_type,
12            signal.size_bytes,
13            signal.source_app,
14            signal.likely_sensitive,
15            signal.likely_command
16        );
17    })?;
18
19    api.request_permission(
20        PermissionRequest::new(
21            Capability::ReadClipboardContent,
22            Scope::Session,
23            "Show how explicit content access works in the example",
24        )
25        .with_ttl(Duration::from_secs(300)),
26    )?;
27
28    if let Ok(content) = api.read_clipboard_content() {
29        println!("initial clipboard preview: {}", content.redacted_preview());
30    }
31
32    println!("Monitoring clipboard changes. Press Ctrl+C to exit.");
33    api.run_with_signals()?;
34    Ok(())
35}
examples/enveloped_clipboard_monitor.rs (lines 25-29)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let mut api = ContextApi::builder()
10        .device_context(DeviceContext {
11            device_id: "desktop:devbox".to_string(),
12            device_name: "devbox".to_string(),
13            platform: Platform::Linux,
14            device_class: DeviceClass::Desktop,
15            os_version: None,
16        })
17        .application_context(ApplicationContext {
18            app_id: "lcsa-demo".to_string(),
19            app_name: "lcsa-demo".to_string(),
20            app_version: Some("0.1.0".to_string()),
21        })
22        .build()?;
23
24    api.request_permission(
25        PermissionRequest::new(
26            Capability::ReadClipboardContent,
27            Scope::Session,
28            "Demonstrate cross-device envelopes plus gated content access",
29        )
30        .with_ttl(Duration::from_secs(300)),
31    )?;
32
33    api.subscribe_enveloped(SignalType::Clipboard, |envelope| {
34        println!(
35            "envelope={} device={} app={} source={:?}",
36            envelope.signal_id,
37            envelope.device.device_id,
38            envelope.application.app_id,
39            envelope.source
40        );
41    })?;
42
43    println!("Monitoring enveloped clipboard signals. Press Ctrl+C to exit.");
44    api.run_with_signals()?;
45    Ok(())
46}
Source

pub fn with_ttl(self, ttl: Duration) -> Self

Examples found in repository?
examples/clipboard_monitor.rs (line 25)
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let mut api = ContextApi::new()?;
7
8    api.subscribe(SignalType::Clipboard, |signal| {
9        println!(
10            "clipboard changed: type={:?}, bytes={}, source={}, sensitive={}, command={}",
11            signal.content_type,
12            signal.size_bytes,
13            signal.source_app,
14            signal.likely_sensitive,
15            signal.likely_command
16        );
17    })?;
18
19    api.request_permission(
20        PermissionRequest::new(
21            Capability::ReadClipboardContent,
22            Scope::Session,
23            "Show how explicit content access works in the example",
24        )
25        .with_ttl(Duration::from_secs(300)),
26    )?;
27
28    if let Ok(content) = api.read_clipboard_content() {
29        println!("initial clipboard preview: {}", content.redacted_preview());
30    }
31
32    println!("Monitoring clipboard changes. Press Ctrl+C to exit.");
33    api.run_with_signals()?;
34    Ok(())
35}
More examples
Hide additional examples
examples/enveloped_clipboard_monitor.rs (line 30)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let mut api = ContextApi::builder()
10        .device_context(DeviceContext {
11            device_id: "desktop:devbox".to_string(),
12            device_name: "devbox".to_string(),
13            platform: Platform::Linux,
14            device_class: DeviceClass::Desktop,
15            os_version: None,
16        })
17        .application_context(ApplicationContext {
18            app_id: "lcsa-demo".to_string(),
19            app_name: "lcsa-demo".to_string(),
20            app_version: Some("0.1.0".to_string()),
21        })
22        .build()?;
23
24    api.request_permission(
25        PermissionRequest::new(
26            Capability::ReadClipboardContent,
27            Scope::Session,
28            "Demonstrate cross-device envelopes plus gated content access",
29        )
30        .with_ttl(Duration::from_secs(300)),
31    )?;
32
33    api.subscribe_enveloped(SignalType::Clipboard, |envelope| {
34        println!(
35            "envelope={} device={} app={} source={:?}",
36            envelope.signal_id,
37            envelope.device.device_id,
38            envelope.application.app_id,
39            envelope.source
40        );
41    })?;
42
43    println!("Monitoring enveloped clipboard signals. Press Ctrl+C to exit.");
44    api.run_with_signals()?;
45    Ok(())
46}

Trait Implementations§

Source§

impl Clone for PermissionRequest

Source§

fn clone(&self) -> PermissionRequest

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PermissionRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PermissionRequest

Source§

fn eq(&self, other: &PermissionRequest) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PermissionRequest

Source§

impl StructuralPartialEq for PermissionRequest

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.