strftime::bytes

Function strftime

Source
pub fn strftime(time: &impl Time, format: &[u8]) -> Result<Vec<u8>, Error>
Available on crate feature alloc only.
Expand description

Format a time implementation with the specified format byte string.

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

§Allocations

This strftime implementation writes its output to a heap-allocated Vec. The implementation exclusively uses fallible allocation APIs like Vec::try_reserve. This function will return Error::OutOfMemory if there is an allocation failure.

§Examples

use strftime::bytes::strftime;
use strftime::Time;

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

assert_eq!(strftime(&time, b"%Y")?, b"1970");

§Errors

Can produce an Error when the formatting fails.