4 releases

new 0.1.4 Mar 5, 2025
0.1.3 Feb 26, 2025
0.1.2 Feb 24, 2025
0.1.1 Feb 21, 2025

#470 in Text processing

Download history

222 downloads per month
Used in 3 crates

MulanPSL-2.0

46KB
1K SLoC

Rust 1K SLoC // 0.0% comments JavaScript 172 SLoC // 0.2% comments CoffeeScript 60 SLoC // 0.3% comments Shell 21 SLoC // 0.1% comments

hpc_captcha

use std::{
  marker::PhantomData,
  sync::atomic::{AtomicBool, Ordering},
};

use aok::Result;

pub trait GenCaptcha {
  fn get() -> impl Future<Output = Result<Vec<u8>>> + Send;
}

pub struct Captcha<G: GenCaptcha> {
  exist: AtomicBool,
  _g: PhantomData<G>,
}

impl<G: GenCaptcha> Default for Captcha<G> {
  fn default() -> Self {
    Self::new()
  }
}

impl<G: GenCaptcha> Captcha<G> {
  pub fn new() -> Self {
    Captcha {
      exist: AtomicBool::new(false),
      _g: PhantomData,
    }
  }

  pub async fn get(&self) -> Result<Vec<u8>> {
    if self.exist.swap(true, Ordering::SeqCst) {
      Ok(vec![])
    } else {
      G::get().await
    }
  }
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Dependencies

~1MB
~17K SLoC