std-method

Waker::will_wake: conservative identity check

Use this method as an optimization for comparing notification targets. A true result guarantees the same task target according to the contract; false does not conclusively establish distinct tasks. A cached waker can use clone_from to update efficiently. Expected stdout (not executed): true Common mistake: Treating a false result as proof that two task identities differ.

Formal Syntax & Structure

rust syntaxrust
a.will_wake(&b) -> bool

Working Example

Example Snippetrust
fn main() {    use std::{future::Future, task::{Context, Poll, Wake, Waker}, sync::{Arc, atomic::{AtomicBool, Ordering}}};    struct Signal(AtomicBool);    impl Wake for Signal {        fn wake(self: Arc<Self>) { self.0.store(true, Ordering::SeqCst); }        fn wake_by_ref(self: &Arc<Self>) { self.0.store(true, Ordering::SeqCst); }    }    let signal = Arc::new(Signal(AtomicBool::new(false)));    let w = Waker::from(Arc::clone(&signal));    let mut cx = Context::from_waker(&w);    let mut cached = w.clone();    cached.clone_from(&w);    println!("{}", cached.will_wake(&w));}
Rust Reference