Expand description
Async stream of clipboard change events.
Provides real-time clipboard monitoring through an async Stream interface.
The main part of this crate is ClipboardStream.
This struct implements Stream.
§Example
The following example shows how to receive clipboard items:
use clipboard_stream::{ClipboardEventListener, Kind};
use futures::stream::StreamExt;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Spawn a clipboard event listener
let mut event_listener = ClipboardEventListener::spawn();
// Create a new stream for UTF-8 strings
// This may return `Error::AlreadyExists` if the same kind of stream already exists
let mut stream = event_listener.new_stream(Kind::Utf8String, 32)?;
while let Some(body) = stream.next().await {
if let Ok(v) = body {
println!("{:?}", v);
}
}
Ok(())
}§Runtime
Internally, this crate spawns a small dedicated OS thread to listen for clipboard events.
The API itself is Future-based and does not depend on any specific async runtime,
so it works with tokio, smol, or any runtime compatible with
futures.
§Platforms
- macOS
Currently supported on macOS only. Windows support is planned for a future release.
Structs§
- Clipboard
Event Listener - Clipboard event change listener.
- Clipboard
Stream - Asynchronous stream for fetching clipboard item.
Enums§
- Body
- Various kind of clipboard items.
- Error
- Represents all the ways a method can fail within clipboard-stream.
- Kind
- Specifies the kind of
ClipboardStream.