mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
add a fmt formatter for Hash20
Summary: We're migrating to fmt, so add a formatter for Hash20. Reviewed By: xavierd Differential Revision: D41104916 fbshipit-source-id: 51ecbd61f1b5ba2fe257cd6ef5835bc9030b1a0a
This commit is contained in:
parent
36cf1e188e
commit
f109c56273
@ -156,5 +156,13 @@ struct hash<facebook::eden::Hash20> {
|
||||
return hash.getHashCode();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<facebook::eden::Hash20> : formatter<string_view> {
|
||||
template <typename Context>
|
||||
auto format(const facebook::eden::Hash20& h, Context& ctx) const {
|
||||
// TODO: Avoid allocation here.
|
||||
return formatter<string_view>::format(h.toString(), ctx);
|
||||
}
|
||||
};
|
||||
|
@ -219,3 +219,10 @@ TEST(Hash20, getHashCode) {
|
||||
// using 64 bits of data to contribute to the hash code.
|
||||
EXPECT_EQ(folly::Endian::big(0xfaceb00cdeadbeef), testHash.getHashCode());
|
||||
}
|
||||
|
||||
TEST(Hash20, formatting) {
|
||||
Hash20 h("0123456789abcdeffedcba987654321076543210");
|
||||
EXPECT_EQ(
|
||||
"0123456789abcdeffedcba987654321076543210", folly::to<std::string>(h));
|
||||
EXPECT_EQ("0123456789abcdeffedcba987654321076543210", fmt::to_string(h));
|
||||
}
|
||||
|
@ -22,9 +22,7 @@
|
||||
#include <folly/lang/Bits.h>
|
||||
#include <folly/logging/xlog.h>
|
||||
#include <folly/portability/GFlags.h>
|
||||
#ifndef _WIN32
|
||||
#include <folly/portability/Unistd.h>
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user