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
22use cfg_if::cfg_if;
23
24// Users should not use the following types directly.
25
26cfg_if! {
27    if #[cfg(feature = "flexible-string")] {
28        // pub for hide type alias in doc
29        #[doc(hidden)]
30        pub type StringBufInner = flexible_string::FlexibleString<STACK_SIZE>;
31    } else {
32        // same as above
33        #[doc(hidden)]
34        pub type StringBufInner = String;
35    }
36}
37
38#[allow(dead_code)]
39pub(crate) const STACK_SIZE: usize = 256;
40#[allow(dead_code)]
41pub(crate) const RESERVE_SIZE: usize = STACK_SIZE / 2;