This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 既存の型への自作trait以外の実装については | |
// newtypeパターンでないと実装できないらしい | |
// いろいろな制約があるとのこと、このあたりは知らん。 | |
use std::fs::File; | |
use std::io::prelude::*; | |
use std::fmt; | |
use std::fmt::Formatter; | |
// 型を新しく定義する(newtype) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs::File; | |
use std::io::prelude::*; | |
fn main(){ | |
let mut file = File::open("src/main.rs").unwrap(); | |
// ベクタを使ってread_to_endしているのはヒープに直接ぶち込みたいから。 | |
// スタックに制約がない場合は、普通の配列を初期化してでもOK | |
// 5回繰り返す。 | |
for i in 0..5{ | |
let mut buf = Vec::<u8>::new(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io; | |
use std::fmt::Display; | |
use std::fmt::Formatter; | |
// オレオレエラー列挙体 | |
#[derive(Debug)] | |
enum myError{ | |
RustError(io::Error), | |
FileError(myFileError), | |
SocketError(mySocketError) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{BufReader,BufWriter,BufRead,Read,Write}; | |
use std::net::{TcpListener, TcpStream}; | |
use std::fs::File; | |
use std::io::prelude::*; | |
// WriteトレイトとReadトレイトを実装しているSugoiTraitを実装すると | |
trait SugoiTrait:Write+Read{ | |
} | |
// TCPストリームも | |
impl SugoiTrait for std::net::TcpStream{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! max { | |
($x:expr) => ( $x ); | |
($x:expr, $($xs:expr),+) => { | |
{ | |
use std::cmp::max; | |
max($x, max!( $($xs),+ )) | |
} | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RGB{ | |
r:u8, | |
g:u8, | |
b:u8 | |
} | |
impl RGB{ | |
fn new()->Self{ | |
Self{ | |
r:0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<stdint.h> | |
typedef struct testVtbl{ | |
int hoihoi[10]; | |
void (*start)(void); | |
void (*end)(void); | |
}TestVTbl; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// タグ名だけ書く。 | |
struct Context; | |
// ステートを管理するためのContext構造体を引数に持ってコールバックを呼びたい | |
// 例えば非同期関数がエラーだった時とかのコールバックや | |
// オブザーバーパターンを実装するときとかによく使うやつ。 | |
typedef struct Callback | |
{ | |
uintmax_t state; //状態の保存 | |
void (*onError)(struct Context* ctx); //ここでContextを渡す関数ポインタを定義する |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
int main(){ | |
// 例のテーブル | |
char tbl[]={ | |
0x4,0xb2,0xf,0x47,0x33,0x84,0x7f,0xdd,0x44,0xbd,0xd6,0x98,0xad, | |
0x83,0xd3,0x34,0x23,0xa1,0x65,0x88,0x73,0xdb,0x95,0xf0 | |
}; | |
// randで生成される数値列を固定する | |
srand(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
a = ["abc","def","cdf","abc","abb"] | |
b = ["abc","def","cdf","abb","zbjl","klgjh","43whyur"] | |
def dupDel(seq): | |
seen = set() | |
seen_add = seen.add |