spdlog/
string_buf.rs

1/// A string buffer type.
2///
3/// Used at [`Formatter`].
4///
5/// By default, it is an alias for [`String`], if feature `flexible-string` is
6/// enabled, an internal type `FlexibleString` will be used.
7///
8/// `FlexibleString` has a fixed stack buffer of 256 bytes, and upgrades to
9/// [`String`] when more space is needed. It provides APIs that are as
10/// consistent as possible with [`String`], but some APIs are not yet
11/// implemented or not possible to be implemented.
12///
13/// <div class="warning">
14///
15/// `FlexibleString` can improve performance as it avoids memory allocation when
16/// formatting records as much as possible, however it contains unsafe code that
17/// has not been strictly reviewed.
18///
19/// </div>
20///
21/// [`Sink`]: crate::sink::Sink
22/// [`Formatter`]: crate::formatter::Formatter
23pub type StringBuf = StringBufInner;
24
25// Users should not use the following types directly.
26
27// pub for hide type alias in doc
28#[doc(hidden)]
29#[cfg(feature = "flexible-string")]
30pub type StringBufInner = flexible_string::FlexibleString<STACK_SIZE>;
31// same as above
32#[doc(hidden)]
33#[cfg(not(feature = "flexible-string"))]
34pub type StringBufInner = String;
35
36#[allow(dead_code)]
37pub(crate) const STACK_SIZE: usize = 256;
38#[allow(dead_code)]
39pub(crate) const RESERVE_SIZE: usize = STACK_SIZE / 2;