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 250 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 cannot be implemented.
12///
13/// # 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.
17///
18/// [`Sink`]: crate::sink::Sink
19/// [`Formatter`]: crate::formatter::Formatter
20pub type StringBuf = StringBufInner;
21
22// Users should not use the following types directly.
23
24// pub for hide type alias in doc
25#[doc(hidden)]
26#[cfg(feature = "flexible-string")]
27pub type StringBufInner = flexible_string::FlexibleString<STACK_SIZE>;
28// same as above
29#[doc(hidden)]
30#[cfg(not(feature = "flexible-string"))]
31pub type StringBufInner = String;
32
33#[allow(dead_code)]
34pub(crate) const STACK_SIZE: usize = 256;
35#[allow(dead_code)]
36pub(crate) const RESERVE_SIZE: usize = STACK_SIZE / 2;