Skip to content

Commit c9df973

Browse files
committed
Implement LogBuffer::uninitialized().
1 parent 1c87cfc commit c9df973

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
sudo: required
22
language: rust
33
rust:
4-
- stable
4+
- nightly
55
env:
66
- secure: "TLRXkqd76FJwSAFOD8kZbieRzWpq6+RA/WrbqLGt9RRL3l65TUEwyDxYoUy5Jscj4bY5XsNPE6CfWggp2SMDcV1C/FNf4nVDTPieCwRluKVHDKpIcoloSVTKihyd6W0P0z9vWNHT7/eYPW+rL8ty2pbFeFJDFJXb1WSIdNcdZvtNHOk8HNKIA/Wiha8/8sHN0EA+EVOIJ3FPYxyQ1NVEYfdQb227LE0UOyTBxU7jke2e/st6GiUl0IPqZy0H38qP5pHismyqsbzlNMsEQqFZrwXE1Zvx3928sD5PBoBfYPsLS3AOz7/nWi/txI3tUm1nlxVzSRF3ZNT5pBmAJof1pBe6+is6C2bxhgTwoTDJBfc2I7fy60dPg3fl9DJWLROBwAaf5Ww2tzuwf0YM3CMSTdI01Y6/RL2n/JBg1h/jRLjZaiqi2rANvBG7iMStVeebJtXkGI0pUpNxTSLBYXBgU+YHwd3rSTXVC4q7Z45q4lsBJohTAWwV29ohz3a97yP+tCfl4KD2QXorV75Vk8A6pl38j1e35xSdWRy3tJp7LFoBqp1g9mz+v+PjZ+8CZ2alPbdp1X5O6Rc6xl1aK76Aw6b/Rz9QGiatEh22FP6EZtMoXhr6oXX+c1B+yqVHrHnPaCUVRfxk2ieg050U5AolXHA9/mxyBbFxzE0wLE3LDe4="
77
after_script:
88
- |
99
if [ "${TRAVIS_BRANCH}" = "master" -a -n "${GH_TOKEN}" ]; then
10-
cargo doc
10+
cargo doc --features=const_fn
1111
git clone https://github.com/davisp/ghp-import
1212
./ghp-import/ghp_import.py -n target/doc
1313
git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ repository = "https://github.com/whitequark/rust-log_buffer"
88
homepage = "https://github.com/whitequark/rust-log_buffer"
99
documentation = "https://whitequark.github.io/rust-log_buffer/log_buffer"
1010
description = "A zero-allocation ring buffer for storing text logs"
11+
12+
[features]
13+
const_fn = []

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! ```
4141
4242
#![no_std]
43+
#![cfg_attr(feature = "const_fn", feature(const_fn))]
4344

4445
/// A ring buffer that stores UTF-8 text.
4546
///
@@ -52,7 +53,7 @@ pub struct LogBuffer<T: AsMut<[u8]>> {
5253
}
5354

5455
impl<T: AsMut<[u8]>> LogBuffer<T> {
55-
/// Creates a new ring buffer, backed by the slice `storage`.
56+
/// Creates a new ring buffer, backed by `storage`.
5657
///
5758
/// The buffer is cleared after creation.
5859
pub fn new(storage: T) -> LogBuffer<T> {
@@ -61,6 +62,16 @@ impl<T: AsMut<[u8]>> LogBuffer<T> {
6162
buffer
6263
}
6364

65+
/// Creates a new ring buffer, backed by `storage`.
66+
///
67+
/// The buffer is *not* cleared after creation, and contains whatever is in `storage`.
68+
/// The `clear()` method should be called before use.
69+
/// However, this function can be used in a static initializer.
70+
#[cfg(feature = "const_fn")]
71+
pub const fn uninitialized(storage: T) -> LogBuffer<T> {
72+
LogBuffer { buffer: storage, position: 0 }
73+
}
74+
6475
/// Clears the buffer.
6576
///
6677
/// Only the text written after clearing will be read out by a future extraction.

0 commit comments

Comments
 (0)