userver: userver/utils/boost_uuid4.hpp Source File
Loading...
Searching...
No Matches
boost_uuid4.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/boost_uuid4.hpp
4/// @brief @copybrief utils::generators::GenerateBoostUuid()
5
6#include <boost/uuid/uuid.hpp>
7
8#include <fmt/core.h>
9#include <userver/utils/fmt_compat.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace utils {
14
15/// Generators
16namespace generators {
17
18/// Generates UUIDv4
19boost::uuids::uuid GenerateBoostUuid();
20
21} // namespace generators
22
23/// Parse string into boost::uuids::uuid
24boost::uuids::uuid BoostUuidFromString(std::string_view str);
25
26/// Serialize boost::uuids::uuid to string
27std::string ToString(const boost::uuids::uuid&);
28
29} // namespace utils
30
31USERVER_NAMESPACE_END
32
33template <>
34struct fmt::formatter<boost::uuids::uuid> {
35 constexpr static auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
36
37 template <typename FormatContext>
38 auto format(const boost::uuids::uuid& uuid, FormatContext& ctx) USERVER_FMT_CONST {
39 return fmt::format_to(ctx.out(), "{}", USERVER_NAMESPACE::utils::ToString(uuid));
40 }
41};