Easy peasy....
mod text;
let mut ctx = raqote::DrawTarget::new(720, 480);
let buffer = text::text(&text::TextProps { text: format!("Hello World"), size: 14 });| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| <link rel="stylesheet" href="/style.css"/> | |
| <style> |
| import sys | |
| import getopt | |
| opts, args = getopt.getopt(sys.argv[1:], '', ['mask=', 'ip=']) | |
| mask_input = list(filter(lambda x: '--mask' in x, opts)) | |
| ip_address_input = list(filter(lambda x: '--ip' in x, opts)) | |
| if len(mask_input) > 0: | |
| maskNum = max(min(int(mask_input[-1][1]), 32), 0) |
| export function toPromise<ReturnType extends any[], ArgTypes extends any[]>(callbackFn: (...args: [...ArgTypes, (err: any, ...data: ReturnType) => void]) => void): (...args: ArgTypes) => Promise<ReturnType> { | |
| return function (...args: ArgTypes): Promise<ReturnType> { | |
| return new Promise(function (resolve) { | |
| callbackFn(...args, (err: any, ...data: ReturnType) => resolve(data)); | |
| }); | |
| }; | |
| } |
| type Option<Parser extends (arg: string) => any> = | |
| ({ long?: string, short: string } | { long: string, short?: string }) | |
| & { format?: Parser, default?: ReturnType<Parser>, description?: string }; | |
| export type Parameters<Names extends { [name: string]: any }> = { [name in keyof Names]: Option<Names[name]> }; | |
| export type Options<Main, Names extends { [name: string]: any }, Config extends Parameters<Names>> = { default: Main } | |
| & { [Parameter in keyof Config]: Config[Parameter] extends Option<(arg: string) => infer Type> ? Type : boolean }; | |
| export default function parse<Main, Names extends { [name: string]: any }>(parameters: Parameters<Names>, main?: (arg: string) => Main): (args: string[]) => Options<Main, Names, typeof parameters> { |
| import fs from 'fs'; | |
| import cp from 'child_process'; | |
| import readline from 'readline'; | |
| export enum Status { | |
| Success = 0, | |
| Unauthorised, | |
| Nonexistent, | |
| Invalid |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <style> | |
| pre, pre code { | |
| font-family: sans-serif; | |
| } | |
| </style> | |
| <meta charset="utf-8"/> | |
| <meta name="viewport" content="width=device-width,initial-scale=1.0"/> |
| use std::fs::{File, OpenOptions}; | |
| use std::io; | |
| use std::os::fd::{AsRawFd, FromRawFd, RawFd}; | |
| use syscall::PAGE_SIZE; | |
| fn main() { | |
| let file = syscall::open(std::env::args().skip(1).next().unwrap(), syscall::O_CLOEXEC | syscall::O_NONBLOCK | syscall::O_RDWR) | |
| .map(|socket| { | |
| unsafe { File::from_raw_fd(socket as RawFd) } | |
| }).unwrap(); |
I like the ? syntax a lot because it is very readable and delegates errors nicely but it often becomes unwieldly because ? only coerces between like-typed error types.
If you define a type which contains each error type and the necessary impls for automatic type coercion, your life becomes much easier.
This macro does that. You define a list of all possible error types, and this macro spits out a system which you need only import.
pub mod error;