cdumay_base64

Crates.iocdumay_base64
lib.rscdumay_base64
version0.1.1
created_at2025-06-19 07:46:33.661082+00
updated_at2025-06-19 14:05:06.428704+00
descriptionA Rust Library for base64
homepagehttps://github.com/cdumay/cdumay_base64
repositoryhttps://github.com/cdumay/cdumay_base64
max_upload_size
id1717937
size17,615
Cédric Dumay (cdumay)

documentation

https://docs.rs/cdumay_base64

README

cdumay_base64

License: BSD-3-Clause cdumay_base64 on crates.io cdumay_base64 on docs.rs Source Code Repository

A small crate to manipulate base64 data.

Features

  • Maps all variants of base64::DecodeError into structured cdumay_core::Error types.
  • Provides unique error codes, HTTP status codes, and human-readable messages.
  • Easily attach contextual metadata for better debugging.
  • Simple integration into any Rust project using base64 and cdumay_core.
  • Provides convenient macro for error conversion

Usage

Using the Base64DecodeErrorConverter directly:

use base64::{engine::general_purpose, Engine as _};
use std::collections::BTreeMap;
use cdumay_core::{ErrorConverter, Error};
use cdumay_base64::Base64DecodeErrorConverter;

fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
    general_purpose::STANDARD.decode(input).map_err(|e| {
        let mut context = BTreeMap::new();
        context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
        Base64DecodeErrorConverter::convert(&e, "Failed to decode base64".to_string(), context)
    })
}

Using the convert_decode_result! macro:

use base64::{engine::general_purpose, Engine as _};
use cdumay_core::{ErrorConverter, Error};
use std::collections::BTreeMap;
use cdumay_base64::convert_decode_result;

fn decode_base64(input: &str) -> cdumay_core::Result<Vec<u8>> {
    let mut context = BTreeMap::new();
    context.insert("input".to_string(), serde_value::Value::String(input.to_string()));
    convert_decode_result!(general_purpose::STANDARD.decode(input), context, "Failed to decode base64")
}
Commit count: 5

cargo fmt