Skip to main content

encode_infallible

Function encode_infallible 

Source
pub fn encode_infallible(input: &[u8]) -> String
Expand description

Encodes input as strict standard padded Base64.

This is a convenience wrapper around Engine::encode_string_infallible on STANDARD for ordinary byte-to-Base64 paths where encoding failure would indicate an internal length/allocation invariant failure rather than invalid input.

Prefer encode when handling untrusted length metadata, constrained allocation environments, or code paths that must return a recoverable error instead of panicking.

§Panics

Panics if encode returns an error. This includes encoded length overflow; on 32-bit targets, inputs larger than roughly 1.5 GiB can overflow the encoded length. For attacker-controlled or externally sized buffers, use encode, which returns a recoverable EncodeError::LengthOverflow.

§Examples

assert_eq!(base64_ng::encode_infallible(b"hello"), "aGVsbG8=");