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 <string_view>
7
8#include <boost/uuid/uuid.hpp>
9
10#include <fmt/core.h>
11#include <userver/utils/fmt_compat.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace utils {
16
17/// @brief Generators, including UUID and random string/id generators.
18namespace generators {
19
20/// Generates UUIDv4
21boost::uuids::uuid GenerateBoostUuid();
22
23} // namespace generators
24
25/// Parse string into boost::uuids::uuid
26boost::uuids::uuid BoostUuidFromString(std::string_view str);
27
28/// Serialize boost::uuids::uuid to string
30
31} // namespace utils
32
33USERVER_NAMESPACE_END
34
35template <>
36struct fmt::formatter<boost::uuids::uuid> {
37 constexpr static auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) { return ctx.begin(); }
38
39 template <typename FormatContext>
40 auto format(const boost::uuids::uuid& uuid, FormatContext& ctx) USERVER_FMT_CONST {
41 return fmt::format_to(ctx.out(), "{}", USERVER_NAMESPACE::utils::ToString(uuid));
42 }
43};