• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013-2014 The Rust Project Developers.
2 // Copyright 2018 The Uuid Project Developers.
3 //
4 // See the COPYRIGHT file at the top-level directory of this distribution.
5 //
6 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 // option. This file may not be copied, modified, or distributed
10 // except according to those terms.
11 
12 use crate::{non_nil::NonNilUuid, Uuid};
13 
14 impl slog::Value for Uuid {
serialize( &self, _: &slog::Record<'_>, key: slog::Key, serializer: &mut dyn slog::Serializer, ) -> Result<(), slog::Error>15     fn serialize(
16         &self,
17         _: &slog::Record<'_>,
18         key: slog::Key,
19         serializer: &mut dyn slog::Serializer,
20     ) -> Result<(), slog::Error> {
21         serializer.emit_arguments(key, &format_args!("{}", self))
22     }
23 }
24 
25 impl slog::Value for NonNilUuid {
serialize( &self, record: &slog::Record<'_>, key: slog::Key, serializer: &mut dyn slog::Serializer, ) -> Result<(), slog::Error>26     fn serialize(
27         &self,
28         record: &slog::Record<'_>,
29         key: slog::Key,
30         serializer: &mut dyn slog::Serializer,
31     ) -> Result<(), slog::Error> {
32         Uuid::from(*self).serialize(record, key, serializer)
33     }
34 }
35 
36 #[cfg(test)]
37 mod tests {
38     use crate::tests::new;
39 
40     use slog::{crit, Drain};
41 
42     #[test]
test_slog_kv()43     fn test_slog_kv() {
44         let root = slog::Logger::root(slog::Discard.fuse(), slog::o!());
45         let u1 = new();
46         crit!(root, "test"; "u1" => u1);
47     }
48 }
49