Skip to main content

ClipboardContent

Struct ClipboardContent 

Source
pub struct ClipboardContent {
    pub payload: ClipboardPayload,
    pub source_app: String,
    pub captured_at: SystemTime,
}

Fields§

§payload: ClipboardPayload§source_app: String§captured_at: SystemTime

Implementations§

Source§

impl ClipboardContent

Source

pub fn redacted_preview(&self) -> String

Examples found in repository?
examples/assistant_context_adapter.rs (line 164)
160fn print_augmented_packet(api: &ContextApi, state: &Arc<Mutex<AdapterState>>, task: &str) {
161    let snapshot = state.lock().expect("adapter state mutex poisoned").clone();
162    let clipboard_preview = api.read_clipboard_content().ok().map(|content| {
163        // The preview intentionally keeps sensitive content redacted when needed.
164        content.redacted_preview()
165    });
166
167    let packet = build_context_packet(api, &snapshot, task, clipboard_preview.clone());
168    println!();
169    println!("=== Augmented Context Packet ===");
170    println!(
171        "{}",
172        serde_json::to_string_pretty(&packet).unwrap_or_default()
173    );
174    println!();
175    println!("=== Prompt Preview ===");
176    println!(
177        "{}",
178        build_prompt_preview(task, &snapshot, clipboard_preview)
179    );
180    println!();
181}
More examples
Hide additional examples
examples/clipboard_monitor.rs (line 29)
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}

Trait Implementations§

Source§

impl Clone for ClipboardContent

Source§

fn clone(&self) -> ClipboardContent

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 ClipboardContent

Source§

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

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

impl<'de> Deserialize<'de> for ClipboardContent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ClipboardContent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,