userver: userver/server/auth/user_id.hpp Source File
Loading...
Searching...
No Matches
user_id.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/auth/user_id.hpp
4/// @brief @copybrief server::auth::UserId
5
6#include <cstdint>
7#include <iosfwd>
8#include <string>
9#include <vector>
10
11#include <userver/formats/parse/to.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace logging {
16class LogHelper;
17}
18
19namespace server::auth {
20
21/// @brief Strongly typed user identifier (uid)
22///
23/// Type that represents a yandex uid and has all the comparison and hashing
24/// operators. It is not implicitly convertible to/from integers and provides
25/// better type safety.
26enum class UserId : std::uint64_t {};
27
28using UserIds = std::vector<UserId>;
29
30template <class Value>
31UserId Parse(const Value& v, formats::parse::To<UserId>) {
32 return UserId{v.template As<std::uint64_t>()};
33}
34
35inline std::uint64_t ToUInt64(UserId v) noexcept { return static_cast<std::uint64_t>(v); }
36
37std::string ToString(UserId v);
38
39template <class Char>
40std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os, UserId v) {
41 return os << ToUInt64(v);
42}
43
44// Optimized output for LogHelper
45logging::LogHelper& operator<<(logging::LogHelper& os, UserId v);
46
47} // namespace server::auth
48
49USERVER_NAMESPACE_END