Skip to content

Instantly share code, notes, and snippets.

View ubnt-intrepid's full-sized avatar
🦀
I may be slow to respond.

Yusuke Sasaki ubnt-intrepid

🦀
I may be slow to respond.
View GitHub Profile
struct Select<A, B>(Option<(A, B)>);
impl<A:Future, B:Future> Future for Select<A, B> {
type Output = Either<(A::Output, B), (A, B::Output)>;
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
// omit
}
}
  • cargo-version-sync
  • colorstring
  • doubter
    • doubter-impl
    • doubter-macros
  • finchers
    • finchers-core
    • finchers-derive
    • finchers-ext
  • finchers-http
@ubnt-intrepid
ubnt-intrepid / main.rs
Last active July 20, 2018 07:33
tsukuyomi 0.3 preview
#[macro_use]
extern crate tsukuyomi;
extern crate http;
use tsukuyomi::App;
use http::Method;
fn establish_db_connection(addr: &str) -> Pool { ... }
fn main() -> tsukuyomi::AppResult<()> {
#[proc_macro_derive(SomeTrait)]
pub fn derive_some_trait_from_def(item: TokenStream) -> TokenStream {
let item: syn::DeriveInput = syn::parse(item).unwrap();
...
}
#[proc_macro_attribute]
pub fn derive_some_trait_from_impl(attr: TokenStream, item: TokenStream) -> TokenStream {
let item: syn::ItemImpl = syn::parse(item).unwrap();
...
@ubnt-intrepid
ubnt-intrepid / Cargo.toml
Last active September 13, 2018 19:43
async/await with Tokio runtime (0.1)
cargo-features = ["edition"]
[package]
name = "async-await-with-tokio"
version = "0.0.0"
publish = false
edition = "2018"
[[bin]]
name = "async-await"
#![feature(test)]
extern crate test;
use test::Bencher;
use test::black_box;
use std::panic::catch_unwind;
fn foo_expect(n: i32) {
let a = bar(n).expect(&format!("n = {}", n));
println!("{}", a);
@ubnt-intrepid
ubnt-intrepid / rfcs.md
Last active July 1, 2018 08:42
気になるRFCなど

Syntax Extension について

手続き的マクロやらcustom Derive周りを制御している周りの調査。 ほとんどソースファイルのコメントに書いていることなので新規性はない。

Procedural macro

Rust は macro_rules! で定義する宣言的 (declarative) なマクロの他に、手続き的 (procedural) なマクロを使用することが出来る。これは、通常のRustコードを用いてマクロ定義を行うものであり、次の利点を持っている。

  • 単純なパターンマッチでは記述の不可能なマクロを定義できる
  • 具象構文を介することなく、抽象構文を直接構築することが出来る
    • asm!() などで用いられている
// format_args!("{0}{1}", a, b)
::std::fmt::Arguments::new_v1(
&["", ""],
&match (&a, &b) {
(__arg0, __arg1) => [
::std::fmt::ArgumentV1::new(__arg0, ::std::fmt::Display::fmt),
::std::fmt::ArgumentV1::new(__arg1, ::std::fmt::Display::fmt),
],
},
)
#![feature(fmt_internals, rustc_private)]
extern crate fmt_macros;
use std::{fmt, io};
#[derive(Default)]
struct ArgumentsBuilder<'a> {
pieces: Vec<&'a str>,
args: Vec<fmt::ArgumentV1<'a>>,