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