Skip to content

Instantly share code, notes, and snippets.

View platy's full-sized avatar
🐟

Mike Bush platy

🐟
View GitHub Profile
@platy
platy / status_codes.rs
Created October 1, 2020 11:03
Changing status codes in paperclip actix-web plugin
use std::fmt;
use actix_http::{Response, Error};
use actix_web::{HttpRequest, Responder};
use actix_web::http::StatusCode;
use futures::future::{err, ok, Ready};
use paperclip::v2::schema::Apiv2Schema;
use paperclip::actix::OperationModifier;
use paperclip::v2::models::{Response as PaperclipResponse, Either, DefaultOperationRaw, DefaultSchemaRaw};
use serde::Serialize;
@platy
platy / permute.rs
Last active October 25, 2022 09:49
Rust array pattern permutation generator macro
/// Use for pattern matching on arrays where you don't care about the order of the items.
/// About the simplest case would be where you have 2 options and need exactly one to be `Some`:
/// ```
/// let input = [Some(42), None];
/// if let permute!([Some(n)], [None]) = input {
/// assert_eq!(n, 42);
/// }
/// ```
/// In this case it matches just like `[Some(n), None] | [None, Some(n)]`, but for more pattern groups it could save a lot more code.
/// The parameters are some number of (comma-separated, square-bracket-enclosed) groups of comma-separated patterns, each group should contain patterns which would match the same inputs, as the ordering of these doesn't need to be permuted.