#actix-web #bincode #web #actix

actix-bincode

Bincode extractor for Actix Web

9 releases

0.3.1 Aug 19, 2024
0.3.0 Jul 3, 2024
0.2.4 Feb 15, 2024
0.2.3 Sep 18, 2023
0.1.1 Nov 11, 2022

#570 in Encoding

Custom license

14KB
204 lines

actix-bincode

crates.io dependency status

Bincode payload extractor for Actix Web

NOTICE: This crate uses Bincode version 2.0.0-rc.3

Example

use actix_bincode::Bincode;
use bincode::{Decode, Encode};

#[derive(Decode, Encode)]
pub struct Object {
    pub num: i32,
    pub text: String,
}

async fn index(object: Bincode<Object>) -> HttpResponse {
    println!("num: {}", object.num);
    println!("text: {}", object.text);
    let config = bincode::config::standard();
    let body = bincode::encode_to_vec(object.into_inner(), config).unwrap();
    HttpResponse::Ok().body(body)
}

Serde example

use actix_bincode::BincodeSerde;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
pub struct Object {
    pub num: i32,
    pub text: String,
}

async fn index(object: BincodeSerde<Object>) -> HttpResponse {
    println!("num: {}", object.num);
    println!("text: {}", object.text);
    let config = bincode::config::standard();
    let body = bincode::serde::encode_to_vec(object.into_inner(), config).unwrap();
    HttpResponse::Ok().body(body)
}

Configuring bincode

Extractor tries to read configuration from actix app data, and defaults to standard if none present:

let config = bincode::config::standard().with_big_endian();

let app = App::new().app_data(config);

License

This project is licensed under

Dependencies

~15–26MB
~445K SLoC