stdweb/webcore/
mutfn.rs

1use std::fmt;
2
3/// A wrapper for passing `FnMut` callbacks into the `js!` macro.
4/// 
5/// Just like when passing regular `Fn` callbacks, don't forget
6/// to `drop()` them on the JavaScript side or else the closure
7/// will be leaked.
8///
9/// # Examples
10///
11/// ```rust
12/// let mut count = 0;
13/// let callback = move || {
14///     count += 1;
15///     println!( "Callback called {} times", count );
16/// };
17/// js! {
18///     var cb = @{Mut(callback)};
19///     cb();
20///     cb();
21///     cb();
22///     cb.drop();
23/// }
24/// ```
25pub struct Mut< T >( pub T );
26
27impl< T > fmt::Debug for Mut< T > {
28    #[inline]
29    fn fmt( &self, formatter: &mut fmt::Formatter ) -> Result< (), fmt::Error > {
30        write!( formatter, "Mut" )
31    }
32}