Skip to main content

Offer

Struct Offer 

Source
pub struct Offer;
Expand description

A promise of text placed on the clipboard, not yet materialized.

Implementations§

Source§

impl Offer

Source

pub fn publish(text: &str) -> Result<Self, Error>

Advertise text on the clipboard without publishing it.

Nothing is copied until a consumer asks, at which point Offer::wait_for_read returns.

Source

pub fn wait_for_read(&self, timeout: Duration) -> bool

Block until a consumer actually read the clipboard, or timeout elapses.

Returns true if the data was read. A false return means the paste never reached the target, which is itself useful: the caller can report that instead of silently assuming success.

Source

pub fn wait_for_reads_to_settle( &self, timeout: Duration, quiet: Duration, ) -> Option<u32>

Wait for the first read, then until reads have been quiet for quiet.

A single WM_RENDERFORMAT is not proof the paste completed. Chromium touches the clipboard more than once per paste — an early probe, then the real read — so restoring after the first render puts the old text back before the read that matters, which is precisely the bug this was meant to fix. Waiting for renders to go quiet covers multi-read consumers.

Returns the number of reads observed, or None if none arrived within timeout.

Source

pub fn read_count(&self) -> u32

Number of times a consumer has asked for the data since publishing.

Source

pub fn mark_paste_sent(&self)

Record that the paste has now been triggered.

Anything that reads the clipboard — a clipboard manager, a history service — satisfies the render, so a read observed before the paste says nothing about the target. Marking here lets Offer::wait_for_target_read ignore those and wait for a read caused by the paste.

Source

pub fn consumed_before_paste(&self) -> bool

Whether the promise was already materialized before the paste was sent.

Once any consumer forces the render, the clipboard holds real data and Windows sends no further WM_RENDERFORMAT. The target’s read is then unobservable — not delayed, gone. A clipboard manager that archives every change causes exactly this, so callers must have a fallback rather than waiting for a signal that can never arrive.

Source

pub fn wait_for_target_read( &self, timeout: Duration, quiet: Duration, ) -> Option<u32>

Wait for a read that happened after Offer::mark_paste_sent, then for reads to settle.

Cannot be satisfied by a clipboard manager that read the promise the moment it was published. Returns None if no such read arrives, which includes the case where the promise was already consumed — check Offer::consumed_before_paste to tell those apart.

Auto Trait Implementations§

§

impl Freeze for Offer

§

impl RefUnwindSafe for Offer

§

impl Send for Offer

§

impl Sync for Offer

§

impl Unpin for Offer

§

impl UnsafeUnpin for Offer

§

impl UnwindSafe for Offer

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> 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, 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.