fn to_string(&self, record: &Record, values: &OwnedKVList) -> slog::Result<String> {
        // This helper structure provides a convenient way to implement
        // `Display` with a closure.
        struct ClosureAsDisplay<F: Fn(&mut fmt::Formatter) -> fmt::Result>(F);
        impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> Display for ClosureAsDisplay<F> {
            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                self.0(f)
            }
        }

        // If there is an error calling `self.fmt`, it will be stored here. We
        // have to use `Cell` because the `Display::fmt` method doesn't get a
        // mutable reference to `self`.
        let result: Cell<Option<slog::Error>> = Cell::new(None);

        // Construct our `Display` implementation…
        let s = ClosureAsDisplay(|f| {
            // Do the formatting.
            if let Err(e) = MsgFormat::fmt(self, f, record, values) {
                // If there's an error, smuggle it out.
                result.set(Some(e));
            }
            // Pretend to succeed, even if there was an error, or else
            // `to_string` will panic.
            Ok(())
        })
        // …and use it to generate a `String`.
        .to_string();

        // Extract the error, if any. It should be waiting inside `result`.
        if let Some(e) = result.take() {
            Err(e)
        } else {
            Ok(s)
        }
    }
/// Formats a log message and its key-value pairs into a new `String`.
Formats a log message and its key-value pairs into a new `String`.
Formats a log message and its key - value pairs into a new ` String ` .
fn to_string(&self, record: &Record, values: &OwnedKVList) -> slog::Result<String> {
        // This helper structure provides a convenient way to implement
        // `Display` with a closure.
        struct ClosureAsDisplay<F: Fn(&mut fmt::Formatter) -> fmt::Result>(F);
        impl<F: Fn(&mut fmt::Formatter) -> fmt::Result> Display for ClosureAsDisplay<F> {
            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                self.0(f)
            }
        }
        // If there is an error calling `self.fmt`, it will be stored here. We
        // have to use `Cell` because the `Display::fmt` method doesn't get a
        // mutable reference to `self`.
        let result: Cell<Option<slog::Error>> = Cell::new(None);
        // Construct our `Display` implementation…
        let s = ClosureAsDisplay(|f| {
            // Do the formatting.
            if let Err(e) = MsgFormat::fmt(self, f, record, values) {
                // If there's an error, smuggle it out.
                result.set(Some(e));
            }
            // Pretend to succeed, even if there was an error, or else
            // `to_string` will panic.
            Ok(())
        })
        // …and use it to generate a `String`.
        .to_string();
        // Extract the error, if any. It should be waiting inside `result`.
        if let Some(e) = result.take() {
            Err(e)
        } else {
            Ok(s)
        }
    }
fn to_string ( & self , record : & Record , values : & OwnedKVList ) -> slog :: Result < String > { // This helper structure provides a convenient way to implement // `Display` with a closure. struct ClosureAsDisplay < F : Fn ( & mut fmt :: Formatter ) -> fmt :: Result > ( F ) ; impl < F : Fn ( & mut fmt :: Formatter ) -> fmt :: Result > Display for ClosureAsDisplay < F > { fn fmt ( & self , f : & mut fmt :: Formatter ) -> fmt :: Result { self . 0 ( f ) } } // If there is an error calling `self.fmt`, it will be stored here. We // have to use `Cell` because the `Display::fmt` method doesn't get a // mutable reference to `self`. let result : Cell < Option < slog :: Error > > = Cell :: new ( None ) ; // Construct our `Display` implementation… let s = ClosureAsDisplay ( | f | { // Do the formatting. if let Err ( e ) = MsgFormat :: fmt ( self , f , record , values ) { // If there's an error, smuggle it out. result . set ( Some ( e ) ) ; } // Pretend to succeed, even if there was an error, or else // `to_string` will panic. Ok ( ( ) ) } ) // …and use it to generate a `String`. . to_string ( ) ; // Extract the error, if any. It should be waiting inside `result`. if let Some ( e ) = result . take ( ) { Err ( e ) } else { Ok ( s ) } }
Formats a log message and its key-value pairs into a new `String`.
Formats a log message and its key - value pairs into a new ` String ` .
&self
record
&Record
values
&OwnedKVList