pub struct Offer;Expand description
A promise of text placed on the clipboard, not yet materialized.
Implementations§
Source§impl Offer
impl Offer
Sourcepub fn publish(text: &str) -> Result<Self, Error>
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.
Sourcepub fn wait_for_read(&self, timeout: Duration) -> bool
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.
Sourcepub fn wait_for_reads_to_settle(
&self,
timeout: Duration,
quiet: Duration,
) -> Option<u32>
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.
Sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Number of times a consumer has asked for the data since publishing.
Sourcepub fn mark_paste_sent(&self)
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.
Sourcepub fn consumed_before_paste(&self) -> bool
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.
Sourcepub fn wait_for_target_read(
&self,
timeout: Duration,
quiet: Duration,
) -> Option<u32>
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.