strftime::buffered

Function strftime

Source
pub fn strftime<'a>(
    time: &impl Time,
    format: &[u8],
    buf: &'a mut [u8],
) -> Result<&'a mut [u8], Error>
Expand description

Format a time implementation with the specified format byte string, writing in the provided buffer and returning the written subslice.

See the crate-level documentation for a complete description of possible format specifiers.

§Allocations

This strftime implementation makes no heap allocations and is usable in a no_std context.

§Examples

use strftime::buffered::strftime;
use strftime::Time;

// Not shown: create a time implementation with the year 1970
// let time = ...;
assert_eq!(time.year(), 1970);

let mut buf = [0u8; 8];
assert_eq!(strftime(&time, b"%Y", &mut buf)?, b"1970");
assert_eq!(buf, *b"1970\0\0\0\0");

§Errors

Can produce an Error when the formatting fails.