stdweb/webcore/
once.rs

1use std::fmt;
2
3/// A wrapper for passing `FnOnce` callbacks into the `js!` macro.
4///
5/// Since it only supports `FnOnce` callbacks there is no need to
6/// `drop()` them manually on the JavaScript side provided they
7/// were actually called.
8///
9/// You still need to `drop()` any callbacks which were **not** called.
10///
11/// # Examples
12///
13/// ```rust
14/// let callback = || { println!( "Hello world!" ); };
15/// js! {
16///     var cb = @{Once(callback)};
17///     cb();
18///     // There is no need to drop it; since the function
19///     // is only callable once it automatically drops
20///     // itself after being called.
21/// }
22/// ```
23pub struct Once< T >( pub T );
24
25impl< T > fmt::Debug for Once< T > {
26    #[inline]
27    fn fmt( &self, formatter: &mut fmt::Formatter ) -> Result< (), fmt::Error > {
28        write!( formatter, "Once" )
29    }
30}