userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
small_string_serialization.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/small_string_serialization.hpp
4
/// @brief Parse, serialize, and fmt formatting for SmallString.
5
/// @ingroup userver_universal
6
7
#
include
<
string
>
8
9
#
include
<
fmt
/
core
.
h
>
10
11
#
include
<
userver
/
formats
/
parse
/
to
.
hpp
>
12
#
include
<
userver
/
formats
/
serialize
/
to
.
hpp
>
13
#
include
<
userver
/
utils
/
small_string
.
hpp
>
14
15
USERVER_NAMESPACE_BEGIN
16
17
namespace
utils
{
18
19
template
<
typename
Value, std::size_t N>
20
Value Serialize(
const
SmallString<N>& value, formats::
serialize
::
To
<Value>) {
21
return
typename
Value::Builder{std::string_view{value}}.ExtractValue();
22
}
23
24
template
<
typename
Value, std::size_t N>
25
SmallString<N> Parse(
const
Value& value, formats::
parse
::
To
<SmallString<N>>) {
26
return
SmallString<N>{value.
template
As<std::string>()};
27
}
28
29
}
// namespace utils
30
31
USERVER_NAMESPACE_END
32
33
template
<std::size_t N>
34
struct
fmt
::
formatter
<USERVER_NAMESPACE::
utils
::SmallString<N>> :
public
fmt::formatter<std::string_view> {
35
template
<
typename
FormatContext>
36
auto
format(
const
USERVER_NAMESPACE::
utils
::SmallString<N>& value, FormatContext& ctx)
const
37
->
decltype
(ctx.out()) {
38
return
formatter<std::string_view>::format(std::string_view{value}, ctx);
39
}
40
};
userver
utils
small_string_serialization.hpp
Generated on
for userver by
Doxygen
1.17.0