├── dotenv ├── .env ├── Cargo.toml └── dotenvy │ ├── src │ ├── dotenvy_with_macro.rs │ └── dotenvy.rs │ ├── Cargo.toml │ └── Cargo.lock ├── README.md ├── databases ├── diesel_mysql │ ├── migrations │ │ ├── .gitkeep │ │ └── 2022-06-18-040851_init │ │ │ ├── down.sql │ │ │ └── up.sql │ ├── Dockerfile │ ├── .env │ ├── diesel.toml │ ├── src │ │ ├── models.rs │ │ ├── schema.rs │ │ ├── lib.rs │ │ └── bin │ │ │ └── example_mysql.rs │ ├── docker-compose.yml │ ├── Cargo.toml │ ├── README.md │ └── Cargo.lock ├── sqlite_sqlite │ ├── Cargo.toml │ ├── src │ │ └── main.rs │ └── Cargo.lock └── rusqlite_sqlite │ ├── Cargo.toml │ ├── src │ └── main.rs │ └── Cargo.lock ├── parser ├── rustfmt.toml ├── Cargo.toml └── src │ ├── parse-ua-woothee.rs │ ├── parse-ua-uap.rs │ └── lib.rs ├── fuse ├── .gitignore ├── README.md ├── Cargo.toml └── src │ └── main.rs ├── nickelapp ├── templates │ ├── index.mustache │ └── index.tera ├── src │ ├── with-mustache.rs │ ├── with-postgres.rs │ ├── with-redis.rs │ ├── with-tera.rs │ ├── with-mysql.rs │ └── with-sqlite.rs └── Cargo.toml ├── .gitignore ├── graphics └── metalexample │ ├── .gitignore │ ├── Cargo.toml │ ├── src │ └── main.rs │ └── Cargo.lock ├── serialize ├── msgpack_rmp │ ├── README.md │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── protobuf │ ├── src │ │ ├── mod.rs │ │ ├── main.rs │ │ └── person.rs │ ├── proto │ │ └── person.proto │ └── Cargo.toml ├── Cargo.toml ├── yaml │ ├── data │ │ └── sample.yml │ ├── Cargo.toml │ └── src │ │ └── parse-yaml.rs └── xml │ ├── Cargo.toml │ ├── src │ ├── xmlrs.rs │ └── quickxml.rs │ └── benches │ └── xmllib.rs ├── extension ├── Cargo.toml ├── pyo3 │ ├── examples │ │ └── is_crawler.py │ ├── Cargo.toml │ ├── setup.py │ └── src │ │ ├── cpy.rs │ │ └── lib.rs ├── cpython │ ├── examples │ │ └── is_crawler.py │ ├── Cargo.toml │ ├── setup.py │ ├── src │ │ └── lib.rs │ └── Cargo.lock └── benchmark │ └── bench.py ├── networking ├── src │ ├── lib.rs │ ├── uds-client.rs │ ├── ssh-command.rs │ ├── sshutil.rs │ ├── scp.rs │ └── nix-tfo-client.rs └── Cargo.toml ├── logging ├── Cargo.toml └── envlogger │ ├── Cargo.toml │ └── src │ ├── simple.rs │ └── myformatter.rs ├── microbench ├── Cargo.toml └── src │ └── lib.rs ├── .github └── dependabot.yml ├── template-engine ├── templates │ └── hello.tera ├── Cargo.toml └── src │ └── tera.rs ├── regex ├── Cargo.toml └── src │ └── lib.rs ├── strum ├── Cargo.toml └── src │ └── main.rs ├── concurrency ├── Cargo.toml └── src │ └── simple.rs ├── messaging ├── Cargo.toml └── src │ └── nats-pub.rs ├── ripgreps ├── ignore-example │ ├── src │ │ ├── main.rs │ │ └── parallel.rs │ └── Cargo.toml └── globset-example │ ├── src │ ├── main.rs │ ├── custom.rs │ └── many.rs │ └── Cargo.toml ├── mio ├── Cargo.toml └── src │ └── uds-client.rs ├── progressbar ├── Cargo.toml └── src │ ├── pbr.rs │ └── progress.rs ├── chan ├── Cargo.toml └── src │ ├── chan.rs │ └── chan-mpmc.rs ├── rpc ├── Cargo.toml └── src │ └── msgpack-rpc-echo.rs ├── http-client ├── src │ ├── url.rs │ ├── http2-solicit.rs │ ├── http-hyper.rs │ ├── ws-client.rs │ ├── get-json-hyper.rs │ ├── rust-websocket-server.rs │ ├── http2-hyper.rs │ └── rust-websocket.rs └── Cargo.toml ├── email ├── Cargo.toml └── src │ ├── lettre-simple.rs │ └── lettre-use-gmail.rs └── parse-cmdline-option ├── Cargo.toml └── src ├── cat-simple.rs ├── cat-docopt.rs ├── cat-argparse.rs ├── cat-getopts.rs └── cat-clap.rs /dotenv/.env: -------------------------------------------------------------------------------- 1 | HOST=example.com 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Rust Code Snippet 2 | -------------------------------------------------------------------------------- /databases/diesel_mysql/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /parser/rustfmt.toml: -------------------------------------------------------------------------------- 1 | max_width = 120 2 | -------------------------------------------------------------------------------- /fuse/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /target/ 3 | **/*.rs.bk 4 | -------------------------------------------------------------------------------- /nickelapp/templates/index.mustache: -------------------------------------------------------------------------------- 1 | Hello {{name}} 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | */Cargo.lock 3 | *.crt 4 | *.key 5 | -------------------------------------------------------------------------------- /graphics/metalexample/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | -------------------------------------------------------------------------------- /databases/diesel_mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql:8.0 2 | 3 | EXPOSE 3306 4 | -------------------------------------------------------------------------------- /serialize/msgpack_rmp/README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | $ cargo run --bin rmp 3 | ``` 4 | -------------------------------------------------------------------------------- /serialize/protobuf/src/mod.rs: -------------------------------------------------------------------------------- 1 | // @generated 2 | 3 | pub mod person; 4 | -------------------------------------------------------------------------------- /databases/diesel_mysql/.env: -------------------------------------------------------------------------------- 1 | DATABASE_URL=mysql://user:password@localhost/diesel_demo 2 | -------------------------------------------------------------------------------- /dotenv/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "dotenvy", 4 | ] 5 | resolver = "2" 6 | -------------------------------------------------------------------------------- /extension/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "cpython", 4 | "pyo3", 5 | ] 6 | -------------------------------------------------------------------------------- /networking/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate ssh2; 2 | extern crate dirs; 3 | 4 | pub mod sshutil; 5 | -------------------------------------------------------------------------------- /logging/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "envlogger", 4 | ] 5 | resolver = "2" 6 | -------------------------------------------------------------------------------- /serialize/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "msgpack_rmp", 4 | "yaml", 5 | "protobuf", 6 | "xml", 7 | ] 8 | -------------------------------------------------------------------------------- /databases/diesel_mysql/migrations/2022-06-18-040851_init/down.sql: -------------------------------------------------------------------------------- 1 | -- This file should undo anything in `up.sql` 2 | DROP TABLE memos; 3 | -------------------------------------------------------------------------------- /serialize/yaml/data/sample.yml: -------------------------------------------------------------------------------- 1 | # minimal.yml 2 | domain: http://localhost:8080 3 | 4 | paths: 5 | - index: / 6 | - hello: /hello 7 | 8 | -------------------------------------------------------------------------------- /microbench/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "microbench" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | 6 | [dependencies] 7 | -------------------------------------------------------------------------------- /serialize/protobuf/proto/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | message Person { 4 | string name = 1; 5 | int32 id = 2; 6 | optional string email = 3; 7 | } 8 | -------------------------------------------------------------------------------- /nickelapp/templates/index.tera: -------------------------------------------------------------------------------- 1 | 2 | hello {{ hello }} 3 | 4 | {% for i in vector %} 5 | {{ i }} 6 | {% endfor %} 7 | 8 | {% if foo %} 9 | {{ foo }} 10 | {% endif %} 11 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "cargo" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | rebase-strategy: "disabled" 8 | -------------------------------------------------------------------------------- /databases/diesel_mysql/diesel.toml: -------------------------------------------------------------------------------- 1 | # For documentation on how to configure this file, 2 | # see diesel.rs/guides/configuring-diesel-cli 3 | 4 | [print_schema] 5 | file = "src/schema.rs" 6 | -------------------------------------------------------------------------------- /databases/diesel_mysql/src/models.rs: -------------------------------------------------------------------------------- 1 | #[derive(Queryable)] 2 | pub struct Memo { 3 | pub id: u32, 4 | pub title: String, 5 | pub body: String, 6 | pub published: bool, 7 | } 8 | -------------------------------------------------------------------------------- /fuse/README.md: -------------------------------------------------------------------------------- 1 | ## memfs 2 | 3 | This is toy project. 4 | 5 | This is on-memory filesystem that lazy implementation in Rust. 6 | 7 | 8 | ## requirements 9 | * rust-fuse. 10 | 11 | -------------------------------------------------------------------------------- /template-engine/templates/hello.tera: -------------------------------------------------------------------------------- 1 | 2 | hello {{ hello }} 3 | 4 | {% for i in vector %} 5 | {{ i }} 6 | {% endfor %} 7 | 8 | {% if foo %} 9 | {{ foo }} 10 | {% endif %} 11 | -------------------------------------------------------------------------------- /databases/sqlite_sqlite/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sqlite_sqlite" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | sqlite = "0.26" 8 | -------------------------------------------------------------------------------- /dotenv/dotenvy/src/dotenvy_with_macro.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate dotenvy_macro; 3 | 4 | const HOST: &str = dotenv!("HOST"); 5 | 6 | fn main() { 7 | println!("HOST: {}", HOST); 8 | } 9 | -------------------------------------------------------------------------------- /databases/rusqlite_sqlite/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rusqlite_sqlite" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | rusqlite = "0.28" 8 | -------------------------------------------------------------------------------- /regex/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "regex" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | 6 | [dependencies] 7 | regex = "*" 8 | 9 | [features] 10 | test = [] 11 | -------------------------------------------------------------------------------- /strum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "strum-example" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | strum = "0.10" 8 | strum_macros = "0.10" 9 | -------------------------------------------------------------------------------- /databases/diesel_mysql/src/schema.rs: -------------------------------------------------------------------------------- 1 | table! { 2 | memos (id) { 3 | id -> Unsigned, 4 | title -> Varchar, 5 | body -> Text, 6 | published -> Bool, 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /graphics/metalexample/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "metalexample" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | metal = "0.29" 9 | image = "0.23" 10 | -------------------------------------------------------------------------------- /concurrency/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "concurrency" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | 6 | [dependencies] 7 | rand = "*" 8 | 9 | [[bin]] 10 | name = "simple" 11 | path = "src/simple.rs" 12 | -------------------------------------------------------------------------------- /fuse/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memfs" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | fuse = "0.3" 8 | log = "0.4" 9 | env_logger = "0.10" 10 | time = "0.3" 11 | libc = "0.2" 12 | -------------------------------------------------------------------------------- /messaging/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "messaging" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | nats = "*" 8 | 9 | [[bin]] 10 | name = "nats-pub" 11 | path = "src/nats-pub.rs" 12 | -------------------------------------------------------------------------------- /serialize/protobuf/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate protobuf; 2 | 3 | mod person; 4 | 5 | fn main() { 6 | let mut person = person::Person::new(); 7 | 8 | person.name = "hoge".to_string(); 9 | 10 | println!("p={:?}", person); 11 | } 12 | -------------------------------------------------------------------------------- /dotenv/dotenvy/src/dotenvy.rs: -------------------------------------------------------------------------------- 1 | use dotenvy::dotenv; 2 | use std::env; 3 | 4 | fn main() { 5 | dotenv().expect(".env file not found"); 6 | 7 | for (key, value) in env::vars() { 8 | println!("{key}: {value}"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /databases/diesel_mysql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | db: 4 | build: 5 | context: . 6 | dockerfile: Dockerfile 7 | ports: 8 | - "3306:3306" 9 | environment: 10 | - MYSQL_ROOT_PASSWORD=password 11 | -------------------------------------------------------------------------------- /serialize/protobuf/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "protobuf" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | protobuf = "3.2.0" 8 | 9 | [[bin]] 10 | name = "protobuf" 11 | path = "src/main.rs" 12 | -------------------------------------------------------------------------------- /databases/diesel_mysql/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "diesel_mysql" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | diesel = { version = "2.2", features = ["mysql"] } 9 | dotenv = "0.15" 10 | -------------------------------------------------------------------------------- /template-engine/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "template-engine" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | tera = "1.1.0" 9 | 10 | [[bin]] 11 | name = "tera" 12 | path = "src/tera.rs" 13 | -------------------------------------------------------------------------------- /serialize/yaml/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "yaml" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | yaml-rust = "*" 8 | rustc-serialize = "0.3" 9 | 10 | [[bin]] 11 | name = "parse-yaml" 12 | path = "src/parse-yaml.rs" 13 | -------------------------------------------------------------------------------- /ripgreps/ignore-example/src/main.rs: -------------------------------------------------------------------------------- 1 | use ignore::Walk; 2 | 3 | fn main() { 4 | for result in Walk::new("./") { 5 | match result { 6 | Ok(entry) => println!("{}", entry.path().display()), 7 | Err(err) => println!("ERROR: {}", err), 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /messaging/src/nats-pub.rs: -------------------------------------------------------------------------------- 1 | extern crate nats; 2 | use nats::*; 3 | 4 | fn main() { 5 | let mut nc = Client::new("nats://127.0.0.1:4222").unwrap(); 6 | nc.set_synchronous(true); 7 | nc.set_name("rust.app"); 8 | 9 | nc.publish("subject", "rust-nats message".as_bytes()).unwrap(); 10 | } 11 | -------------------------------------------------------------------------------- /mio/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "mio" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | mio = "0.5" 8 | 9 | [dependencies.bytes] 10 | git = "https://github.com/carllerche/bytes" 11 | 12 | [[bin]] 13 | name = "uds-client" 14 | path = "src/uds-client.rs" 15 | -------------------------------------------------------------------------------- /extension/pyo3/examples/is_crawler.py: -------------------------------------------------------------------------------- 1 | import fast_woothee_pyo3 as woothee 2 | 3 | ua = "Mozilla" 4 | ret = woothee.is_crawler(ua) 5 | print(ret) 6 | 7 | ua = "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.5; Trident/3.1; IEMobile/7.0; FujitsuToshibaMobileCommun; IS12T; KDDI)" 8 | ret = woothee.parse(ua) 9 | print(ret) 10 | -------------------------------------------------------------------------------- /progressbar/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "progressbar" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | progress = "0.1" 8 | pbr = "1.0" 9 | 10 | [[bin]] 11 | name = "progress" 12 | path = "src/progress.rs" 13 | 14 | [[bin]] 15 | name = "pbr" 16 | path = "src/pbr.rs" 17 | -------------------------------------------------------------------------------- /databases/diesel_mysql/migrations/2022-06-18-040851_init/up.sql: -------------------------------------------------------------------------------- 1 | -- Your SQL goes here 2 | CREATE TABLE memos ( 3 | `id` INT UNSIGNED AUTO_INCREMENT, 4 | `title` VARCHAR(255) NOT NULL, 5 | `body` TEXT NOT NULL, 6 | `published` BOOLEAN NOT NULL DEFAULT false, 7 | PRIMARY KEY (`id`) 8 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 9 | -------------------------------------------------------------------------------- /extension/cpython/examples/is_crawler.py: -------------------------------------------------------------------------------- 1 | import fast_woothee_cpy as woothee 2 | 3 | ua = "Mozilla" 4 | ret = woothee.is_crawler(ua) 5 | print(ret) 6 | 7 | ua = "Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.5; Trident/3.1; IEMobile/7.0; FujitsuToshibaMobileCommun; IS12T; KDDI)" 8 | ret = woothee.parse(ua) 9 | print(ret) 10 | -------------------------------------------------------------------------------- /chan/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "chan" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | chan = "*" 8 | chan-signal = "*" 9 | #lockless = "*" 10 | 11 | [[bin]] 12 | name = "chan" 13 | path = "src/chan.rs" 14 | 15 | [[bin]] 16 | name = "chan-mpmc" 17 | path = "src/chan-mpmc.rs" 18 | -------------------------------------------------------------------------------- /extension/pyo3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "pyo3-woothee" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [lib] 7 | name = "woothee" 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | woothee = "0.8" 12 | 13 | [dependencies.pyo3] 14 | version = "0.16" 15 | features = ["extension-module"] 16 | -------------------------------------------------------------------------------- /rpc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rpc" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | msgpack-rpc = { git = "https://github.com/euclio/msgpack-rpc-rust.git", branch = "master" } 8 | rmp = "0.7" 9 | 10 | [[bin]] 11 | name = "msgpack-rpc" 12 | path = "src/msgpack-rpc-echo.rs" 13 | -------------------------------------------------------------------------------- /extension/cpython/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fast-woothee" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [lib] 7 | name = "woothee" 8 | crate-type = ["cdylib"] 9 | 10 | [dependencies] 11 | woothee = "0.13" 12 | 13 | [dependencies.cpython] 14 | version = "0.7" 15 | features = ["extension-module"] 16 | -------------------------------------------------------------------------------- /parser/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "parser" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | 6 | [dependencies] 7 | woothee = "0.4" 8 | uap-rust = "*" 9 | 10 | [[bin]] 11 | name = "parse-ua-woothee" 12 | path = "src/parse-ua-woothee.rs" 13 | 14 | [[bin]] 15 | name = "parse-ua-uap" 16 | path = "src/parse-ua-uap.rs" 17 | -------------------------------------------------------------------------------- /networking/src/uds-client.rs: -------------------------------------------------------------------------------- 1 | extern crate unix_socket; 2 | 3 | use std::env; 4 | use std::io::prelude::*; 5 | use unix_socket::UnixStream; 6 | 7 | fn main() { 8 | let socket_path = env::args().skip(1).next().unwrap(); 9 | let mut stream = UnixStream::connect(socket_path.as_str()).unwrap(); 10 | stream.write_all(b"hello").unwrap(); 11 | } 12 | -------------------------------------------------------------------------------- /serialize/xml/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "xml" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | quick-xml = "0.29" 8 | xml-rs = "0.8" 9 | 10 | [[bin]] 11 | name = "quickxml" 12 | path = "src/quickxml.rs" 13 | 14 | [[bin]] 15 | name = "xmlrs" 16 | path = "src/xmlrs.rs" 17 | 18 | [features] 19 | test = [] 20 | -------------------------------------------------------------------------------- /dotenv/dotenvy/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dotenvy" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | dotenvy = "0.15" 9 | dotenvy_macro = "0.15" 10 | 11 | [[bin]] 12 | name = "dotenvy" 13 | path = "src/dotenvy.rs" 14 | 15 | [[bin]] 16 | name = "dotenvy_with_macro" 17 | path = "src/dotenvy_with_macro.rs" 18 | -------------------------------------------------------------------------------- /http-client/src/url.rs: -------------------------------------------------------------------------------- 1 | extern crate url; 2 | use url::Url; 3 | 4 | fn main() { 5 | let url = Url::parse("http://localhost:7777/").expect("fail Url::parse()"); 6 | let mut target_url = url.join("/hello").expect("fail url join()"); 7 | target_url.set_query(Some("hoge=fuga")); 8 | target_url.set_query(Some("t=zzz")); 9 | 10 | println!("{}", target_url); 11 | } 12 | -------------------------------------------------------------------------------- /ripgreps/ignore-example/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ignore-example" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | ignore = "0.4" 9 | crossbeam-channel = "0.5" 10 | 11 | [[bin]] 12 | name = "simple" 13 | path = "src/main.rs" 14 | 15 | [[bin]] 16 | name = "parallel" 17 | path = "src/parallel.rs" 18 | -------------------------------------------------------------------------------- /serialize/msgpack_rmp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "msgpack_rmp" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | rmp = "0.8" 10 | rmp-serde = "1" 11 | serde = "1" 12 | serde_derive = "1" 13 | 14 | [[bin]] 15 | name = "rmp" 16 | path = "src/main.rs" 17 | -------------------------------------------------------------------------------- /email/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "email" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | lettre = "0.9" 9 | lettre_email = "0.9" 10 | mime = "0.3" 11 | 12 | [[bin]] 13 | name = "lettre-simple" 14 | path = "src/lettre-simple.rs" 15 | 16 | [[bin]] 17 | name = "lettre-use-gmail" 18 | path = "src/lettre-use-gmail.rs" 19 | -------------------------------------------------------------------------------- /ripgreps/globset-example/src/main.rs: -------------------------------------------------------------------------------- 1 | use globset::Glob; 2 | 3 | fn main() { 4 | let glob = Glob::new("*.rs").unwrap().compile_matcher(); 5 | 6 | for name in vec!["foo.rs", "foo/bar.rs", "Cargo.toml"] { 7 | if glob.is_match(name) { 8 | println!("{} is match", name); 9 | } else { 10 | println!("{} is not match", name); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /ripgreps/globset-example/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "globset-example" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | globset = "0.3" 9 | 10 | [[bin]] 11 | name = "simple" 12 | path = "src/main.rs" 13 | 14 | [[bin]] 15 | name = "custom" 16 | path = "src/custom.rs" 17 | 18 | [[bin]] 19 | name = "many" 20 | path = "src/many.rs" 21 | -------------------------------------------------------------------------------- /extension/pyo3/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools_rust import Binding, RustExtension 3 | 4 | 5 | setup(name='fast-woothee-pyo3', 6 | version='0.1', 7 | rust_extensions=[ 8 | RustExtension('fast_woothee_pyo3', 'Cargo.toml', 9 | binding=Binding.PyO3)], 10 | # rust extensions are not zip safe, just like C-extensions. 11 | zip_safe=False) 12 | -------------------------------------------------------------------------------- /extension/cpython/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | from setuptools_rust import Binding, RustExtension 3 | 4 | 5 | setup(name='fast-woothee-cpy', 6 | version='0.1', 7 | rust_extensions=[ 8 | RustExtension('fast_woothee_cpy', 'Cargo.toml', 9 | binding=Binding.RustCPython)], 10 | # rust extensions are not zip safe, just like C-extensions. 11 | zip_safe=False) 12 | -------------------------------------------------------------------------------- /logging/envlogger/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "envlogger" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | log = "0.4" 9 | env_logger = "0.11" 10 | time = { version = "0.3", features = ["formatting"] } 11 | 12 | [[bin]] 13 | name = "simple" 14 | path = "src/simple.rs" 15 | 16 | [[bin]] 17 | name = "myformatter" 18 | path = "src/myformatter.rs" 19 | -------------------------------------------------------------------------------- /databases/diesel_mysql/README.md: -------------------------------------------------------------------------------- 1 | ## requirements 2 | 3 | install `diesel_cli`: 4 | 5 | ``` 6 | $ cargo install diesel_cli 7 | ``` 8 | 9 | start mysql: 10 | 11 | ``` 12 | $ docker compose up --build -d 13 | ``` 14 | 15 | ## exaple of mysql access with Diesel 16 | 17 | ``` 18 | echo DATABASE_URL=mysql://root:password@0.0.0.0/diesel_demo > .env 19 | $ diesel setup 20 | $ diesel migration run 21 | $ cargo run --bin example_mysql 22 | ``` 23 | -------------------------------------------------------------------------------- /progressbar/src/pbr.rs: -------------------------------------------------------------------------------- 1 | extern crate pbr; 2 | 3 | use pbr::ProgressBar; 4 | use std::thread; 5 | use std::time::Duration; 6 | 7 | fn simple() { 8 | const MAX: u64 = 10; 9 | let mut pb = ProgressBar::new(MAX); 10 | pb.format("╢▌▌░╟"); 11 | for _ in 0..MAX { 12 | pb.inc(); 13 | thread::sleep(Duration::from_millis(100)); 14 | } 15 | pb.finish_print("done") 16 | } 17 | 18 | fn main() { 19 | simple(); 20 | } 21 | -------------------------------------------------------------------------------- /progressbar/src/progress.rs: -------------------------------------------------------------------------------- 1 | extern crate progress; 2 | 3 | use std::thread; 4 | use std::time::Duration; 5 | 6 | fn main() { 7 | let mut bar = progress::Bar::new(); 8 | bar.set_job_title("example"); 9 | 10 | const MAX: i32 = 20; 11 | 12 | for _ in 0..MAX { 13 | thread::sleep(Duration::from_millis(100)); 14 | bar.add_percent(100 / MAX); 15 | } 16 | 17 | bar.reach_percent(100); 18 | bar.jobs_done(); 19 | } 20 | -------------------------------------------------------------------------------- /databases/diesel_mysql/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate diesel; 3 | 4 | pub mod models; 5 | pub mod schema; 6 | 7 | use diesel::mysql::MysqlConnection; 8 | use diesel::prelude::*; 9 | use dotenv::dotenv; 10 | use std::env; 11 | 12 | pub fn establish_connection() -> MysqlConnection { 13 | dotenv().ok(); 14 | 15 | let database_url = env::var("DATABASE_URL").expect("env must be set"); 16 | MysqlConnection::establish(&database_url).expect("error") 17 | } 18 | -------------------------------------------------------------------------------- /ripgreps/globset-example/src/custom.rs: -------------------------------------------------------------------------------- 1 | use globset::GlobBuilder; 2 | 3 | fn main() { 4 | let glob = GlobBuilder::new("bar.rs") 5 | .case_insensitive(true) 6 | .build().unwrap().compile_matcher(); 7 | 8 | for name in vec!["bar.rs", "baR.rs", "foo/bar.rs", "Cargo.toml"] { 9 | if glob.is_match(name) { 10 | println!("{} is match", name); 11 | } else { 12 | println!("{} is not match", name); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /http-client/src/http2-solicit.rs: -------------------------------------------------------------------------------- 1 | extern crate solicit; 2 | use solicit::http::client::CleartextConnector; 3 | use solicit::client::SimpleClient; 4 | use std::str; 5 | 6 | static HOST: &'static str = "nghttp2.org"; 7 | 8 | fn main() { 9 | let connector = CleartextConnector::new(HOST); 10 | let mut client = SimpleClient::with_connector(connector).unwrap(); 11 | let resp = client.get(b"/httpbin/get", &[]).unwrap(); 12 | 13 | println!("{}", str::from_utf8(&resp.body).unwrap()); 14 | } 15 | -------------------------------------------------------------------------------- /parser/src/parse-ua-woothee.rs: -------------------------------------------------------------------------------- 1 | extern crate woothee; 2 | use woothee::parser::Parser; 3 | 4 | fn main() { 5 | let parser = Parser::new(); 6 | let mut result = parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"); 7 | println!("{:?}", result); 8 | 9 | result = parser.parse("Twitterbot/1.0"); 10 | println!("{:?}", result); 11 | 12 | result = parser.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)"); 13 | println!("{:?}", result); 14 | } 15 | -------------------------------------------------------------------------------- /networking/src/ssh-command.rs: -------------------------------------------------------------------------------- 1 | extern crate networking; 2 | use networking::sshutil; 3 | use std::io::prelude::*; 4 | 5 | static USERNAME: &'static str = "username"; 6 | static REMOTE_ADDRESS: &'static str = "127.0.0.1:22"; 7 | 8 | fn main() { 9 | let (_tcp, session) = sshutil::ssh_login(REMOTE_ADDRESS, USERNAME); 10 | 11 | let mut chan = session.channel_session().unwrap(); 12 | chan.exec("ls").unwrap(); 13 | let mut s = String::new(); 14 | chan.read_to_string(&mut s).unwrap(); 15 | println!("{}", s); 16 | } 17 | -------------------------------------------------------------------------------- /databases/diesel_mysql/src/bin/example_mysql.rs: -------------------------------------------------------------------------------- 1 | extern crate diesel; 2 | extern crate diesel_mysql; 3 | 4 | use self::models::*; 5 | use diesel::prelude::*; 6 | use diesel_mysql::*; 7 | 8 | fn main() { 9 | use self::schema::memos::dsl::*; 10 | 11 | let mut dbconn = establish_connection(); 12 | let results = memos.limit(5).load::(&mut dbconn).expect("select error"); 13 | 14 | for memo in results { 15 | println!( 16 | "{}, {}, {}, {}", 17 | memo.id, memo.title, memo.body, memo.published 18 | ); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /networking/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "networking" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | ssh2 = "0.2" 8 | unix_socket = "0.5" 9 | dirs = "1.0" 10 | nix = { git = "https://github.com/hhatto/nix.git", branch = "tfo" } 11 | 12 | [[bin]] 13 | name = "ssh-command" 14 | path = "src/ssh-command.rs" 15 | 16 | [[bin]] 17 | name = "scp" 18 | path = "src/scp.rs" 19 | 20 | [[bin]] 21 | name = "uds-client" 22 | path = "src/uds-client.rs" 23 | 24 | [[bin]] 25 | name = "nix-tfo-client" 26 | path = "src/nix-tfo-client.rs" 27 | -------------------------------------------------------------------------------- /networking/src/sshutil.rs: -------------------------------------------------------------------------------- 1 | use ssh2::Session; 2 | use std::net::TcpStream; 3 | 4 | pub fn ssh_login(addr: &'static str, username: &'static str) -> (TcpStream, Session) { 5 | let tcp = TcpStream::connect(addr).unwrap(); 6 | let mut session = Session::new().unwrap(); 7 | session.handshake(&tcp).unwrap(); 8 | let privatekey_filepath = dirs::home_dir().unwrap().join(".ssh/id_rsa"); 9 | session.userauth_pubkey_file(username, None, privatekey_filepath.as_path(), None) 10 | .unwrap(); 11 | 12 | assert!(session.authenticated()); 13 | (tcp, session) 14 | } 15 | -------------------------------------------------------------------------------- /ripgreps/globset-example/src/many.rs: -------------------------------------------------------------------------------- 1 | use globset::{Glob, GlobSetBuilder}; 2 | 3 | fn main() { 4 | let mut builder = GlobSetBuilder::new(); 5 | builder.add(Glob::new("foo/{foo,bar}.rs").unwrap()); 6 | builder.add(Glob::new("Cargo.*").unwrap()); 7 | 8 | let globs = builder.build().unwrap(); 9 | for name in vec!["foo/foo.rs", "foo/bar.rs", "foo/baz.rs", "Cargo.toml", "Cargo.lock"] { 10 | if globs.is_match(name) { 11 | println!("{} is match", name); 12 | } else { 13 | println!("{} is not match", name); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /email/src/lettre-simple.rs: -------------------------------------------------------------------------------- 1 | use lettre::{SmtpClient, Transport}; 2 | use lettre_email::EmailBuilder; 3 | 4 | fn sendmail_with_file() { 5 | let mut sender = SmtpClient::new_unencrypted_localhost().unwrap().transport(); 6 | let email = EmailBuilder::new() 7 | .from("from-address@localhost") 8 | .to("to-address@localhost") 9 | .subject("Message-ID") 10 | .body("Hello rust mail body".to_string()) 11 | .build().expect("fail to build email"); 12 | 13 | let result = sender.send(email.into()); 14 | println!("{}", result.is_ok()); 15 | } 16 | 17 | fn main() { 18 | sendmail_with_file(); 19 | } 20 | -------------------------------------------------------------------------------- /parse-cmdline-option/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "parse-cmdline-option" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | 6 | [dependencies] 7 | getopts = "*" 8 | docopt = "1.0" 9 | serde = "1.0" 10 | serde_derive = "1.0" 11 | argparse = "*" 12 | clap = "2" 13 | 14 | [[bin]] 15 | name = "cat-simple" 16 | path = "src/cat-simple.rs" 17 | 18 | [[bin]] 19 | name = "cat-getopts" 20 | path = "src/cat-getopts.rs" 21 | 22 | [[bin]] 23 | name = "cat-docopt" 24 | path = "src/cat-docopt.rs" 25 | 26 | [[bin]] 27 | name = "cat-argparse" 28 | path = "src/cat-argparse.rs" 29 | 30 | [[bin]] 31 | name = "cat-clap" 32 | path = "src/cat-clap.rs" 33 | -------------------------------------------------------------------------------- /nickelapp/src/with-mustache.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nickel; 3 | extern crate nickel_mustache; 4 | extern crate rustc_serialize; 5 | 6 | // use nickel_mustache::Render; 7 | use nickel::{Nickel, HttpRouter}; 8 | 9 | fn main() { 10 | let mut server = Nickel::new(); 11 | 12 | server.get("/*", 13 | middleware! { |_req, res| 14 | #[derive(RustcEncodable)] 15 | struct ViewData<'a> { 16 | name: &'a str 17 | } 18 | 19 | let data = ViewData { name: "World" }; 20 | 21 | return res.render("templates/index.mustache", &data) 22 | }); 23 | 24 | server.listen("127.0.0.1:6767"); 25 | } 26 | -------------------------------------------------------------------------------- /parser/src/parse-ua-uap.rs: -------------------------------------------------------------------------------- 1 | extern crate uap_rust; 2 | use uap_rust::parser::Parser; 3 | 4 | fn main() { 5 | let parser = Parser::new().unwrap(); 6 | let mut result = parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; \ 7 | Trident/4.0)" 8 | .to_string()); 9 | println!("{:?}", result); 10 | 11 | result = parser.parse("Twitterbot/1.0".to_string()); 12 | println!("{:?}", result); 13 | 14 | result = parser.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)" 15 | .to_string()); 16 | println!("{:?}", result); 17 | } 18 | -------------------------------------------------------------------------------- /nickelapp/src/with-postgres.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nickel; 3 | extern crate nickel_postgres; 4 | 5 | use std::env; 6 | use nickel::{Nickel, HttpRouter}; 7 | use nickel_postgres::{PostgresMiddleware, PostgresRequestExtensions}; 8 | 9 | fn main() { 10 | let mut app = Nickel::new(); 11 | 12 | let postgres_url = env::var("DATABASE_URL").unwrap(); 13 | let mw = PostgresMiddleware::new(&postgres_url).unwrap(); 14 | app.utilize(mw); 15 | 16 | app.get("/my_counter", 17 | middleware! { |request, response| 18 | let _connection = try_with!(response, request.pg_conn()); 19 | 20 | // use connection 21 | }); 22 | 23 | app.get("**", middleware! { println!("!!!") }); 24 | } 25 | -------------------------------------------------------------------------------- /concurrency/src/simple.rs: -------------------------------------------------------------------------------- 1 | extern crate rand; 2 | use std::thread; 3 | use std::time::Duration; 4 | use rand::random; 5 | 6 | const NUM_THREADS: i32 = 10; 7 | 8 | fn task(arg: i32) -> (i32, u32) { 9 | let x = random::(); 10 | let s = x % 5000; 11 | thread::sleep(Duration::from_millis(s as u64)); 12 | (arg, s) 13 | } 14 | 15 | fn main() { 16 | let mut handles = vec![]; 17 | for i in 0..NUM_THREADS { 18 | handles.push(thread::spawn(move || task(i))); 19 | } 20 | 21 | for _ in 0..NUM_THREADS { 22 | let handle = handles.pop().unwrap(); 23 | let (thread_arg, sleep_time) = handle.join().unwrap(); 24 | println!("thread=[{}] sleep {:?}msec", thread_arg, sleep_time); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /http-client/src/http-hyper.rs: -------------------------------------------------------------------------------- 1 | use std::io::Read; 2 | use hyper::Client; 3 | use hyper::body::Buf; 4 | use hyper_tls::HttpsConnector; 5 | 6 | static URL: &'static str = "https://httpbin.org/get"; 7 | 8 | #[tokio::main] 9 | async fn main() -> Result<(), Box> { 10 | let https = HttpsConnector::new(); 11 | let client = Client::builder().build::<_, hyper::Body>(https); 12 | let res = client.get(URL.parse()?).await?; 13 | 14 | let body = hyper::body::aggregate(res).await?; 15 | let mut bbody = String::new(); 16 | 17 | match body.reader().read_to_string(&mut bbody) { 18 | Ok(_) => println!("{}", bbody), 19 | Err(e) => println!("error: {}", e), 20 | }; 21 | 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /template-engine/src/tera.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::path::Path; 3 | use tera::{Tera, Context}; 4 | 5 | fn main() { 6 | let root_path = env::current_dir().unwrap(); 7 | let template_dir = root_path.join(Path::new("templates/*.tera")); 8 | let template_engine = match Tera::new(template_dir.to_str().unwrap()) { 9 | Ok(t) => t, 10 | Err(e) => panic!("tera::new error: {}", e), 11 | }; 12 | let mut context = Context::new(); 13 | 14 | let foo = ""; 15 | let hello = "world"; 16 | let vector = vec![1, 3, 6]; 17 | context.insert("foo", &foo); 18 | context.insert("hello", &hello); 19 | context.insert("vector", &vector); 20 | println!("{}", template_engine.render("hello.tera", &context).unwrap()); 21 | } 22 | -------------------------------------------------------------------------------- /parse-cmdline-option/src/cat-simple.rs: -------------------------------------------------------------------------------- 1 | use std::io::prelude::*; 2 | use std::error::Error; 3 | use std::fs::File; 4 | use std::path::Path; 5 | 6 | fn main() { 7 | for arg in std::env::args().skip(1) { 8 | let path = Path::new(&arg); 9 | let display = path.display(); 10 | 11 | let mut f = match File::open(&path) { 12 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 13 | Ok(file) => file, 14 | }; 15 | 16 | let mut s = String::new() ; 17 | match f.read_to_string(&mut s) { 18 | Err(why) => panic!("could not read {}: {}", display, Error::description(&why)), 19 | Ok(_) => print!("=== {} ===\n{}", display, s), 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ripgreps/ignore-example/src/parallel.rs: -------------------------------------------------------------------------------- 1 | use std::thread; 2 | use ignore::{DirEntry, WalkBuilder}; 3 | use crossbeam_channel as channel; 4 | 5 | fn main() { 6 | let (tx, rx) = channel::bounded::(100); 7 | let mut builder = WalkBuilder::new("./"); 8 | 9 | let stdout_thread = thread::spawn(move || { 10 | for dent in rx { 11 | println!("{}", dent.path().to_str().unwrap()); 12 | } 13 | }); 14 | 15 | builder.threads(8).build_parallel().run(|| { 16 | let tx = tx.clone(); 17 | Box::new(move |result| { 18 | use ignore::WalkState::*; 19 | 20 | let _ = tx.send(result.unwrap()); 21 | Continue 22 | }) 23 | }); 24 | 25 | drop(tx); 26 | stdout_thread.join().unwrap(); 27 | } 28 | -------------------------------------------------------------------------------- /strum/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate strum; 2 | #[macro_use] 3 | extern crate strum_macros; 4 | use std::str::FromStr; 5 | use std::string::ToString; 6 | 7 | #[derive(ToString, EnumString, Debug)] 8 | enum Browser { 9 | Chrome, 10 | Firefox, 11 | 12 | #[strum(disabled="true")] 13 | IE, 14 | 15 | #[strum(serialize="Microsoft Edge")] 16 | Edge 17 | } 18 | 19 | fn main() { 20 | let b = Browser::IE; 21 | println!("{:?}", b); 22 | let b = Browser::from_str("Chrome").unwrap(); 23 | println!("{:?}", b); 24 | let b = match Browser::from_str("IE") { 25 | Ok(v) => v, 26 | Err(e) => { println!("disabled enum, error: {:?}", e); Browser::IE }, 27 | }; 28 | println!("{:?}", b); 29 | 30 | let b = Browser::Edge; 31 | println!("{}, {:?}", b.to_string(), b); 32 | } 33 | -------------------------------------------------------------------------------- /nickelapp/src/with-redis.rs: -------------------------------------------------------------------------------- 1 | extern crate r2d2; 2 | extern crate redis; 3 | #[macro_use] 4 | extern crate nickel; 5 | extern crate nickel_redis; 6 | extern crate core; 7 | 8 | use std::env; 9 | use r2d2::NopErrorHandler; 10 | use nickel::{Nickel, HttpRouter}; 11 | use nickel_redis::{RedisMiddleware, RedisRequestExtensions}; 12 | use core::ops::Deref; 13 | 14 | fn main() { 15 | let mut app = Nickel::new(); 16 | 17 | let redis_url = env::var("DATABASE_URL").unwrap(); 18 | let dbpool = RedisMiddleware::new(&*redis_url, 5, Box::new(NopErrorHandler)).unwrap(); 19 | app.utilize(dbpool); 20 | app.get("/my_counter", 21 | middleware! { |request| 22 | let pool_con = request.redis_conn(); 23 | let _con = pool_con.deref(); 24 | 25 | // Use con as your connection 26 | }); 27 | 28 | app.get("**", middleware! { println!("!!!") }); 29 | } 30 | -------------------------------------------------------------------------------- /rpc/src/msgpack-rpc-echo.rs: -------------------------------------------------------------------------------- 1 | extern crate msgpack_rpc; 2 | extern crate rmp as msgpack; 3 | 4 | use std::thread; 5 | use msgpack::Value; 6 | use msgpack_rpc::{Server, Dispatch, Client}; 7 | 8 | #[derive(Clone, Default)] 9 | struct EchoServer; 10 | 11 | impl Dispatch for EchoServer { 12 | fn dispatch(&mut self, method: &str, args: Vec) -> Result { 13 | match method { 14 | "hello" => Ok(Value::Array(args.to_owned())), 15 | _ => Err(Value::String("Invalid method name.".to_owned())), 16 | } 17 | } 18 | } 19 | 20 | fn main() { 21 | let server = Server::bind("localhost:10009").unwrap(); 22 | let mut client = Client::connect_socket(server.local_addr().unwrap()); 23 | 24 | thread::spawn(move || { 25 | server.handle(EchoServer); 26 | }); 27 | 28 | let ret = client.call("hello", vec![Value::String("Hello msgpack-rpc".to_owned())]); 29 | println!("{:?}", ret); 30 | } 31 | -------------------------------------------------------------------------------- /nickelapp/src/with-tera.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nickel; 3 | extern crate nickel_tera; 4 | extern crate tera; 5 | 6 | use std::env; 7 | use std::path::Path; 8 | use tera::{Tera, Context}; 9 | use nickel::{Nickel, HttpRouter}; 10 | 11 | fn main() { 12 | let mut server = Nickel::new(); 13 | 14 | let root_path = env::current_dir().unwrap(); 15 | let template_dir = root_path.join(Path::new("templates/*.tera")); 16 | let template_engine = Tera::new(template_dir.to_str().unwrap()); 17 | 18 | server.get("/*", 19 | middleware! { |req, res| 20 | let mut ctx = Context::new(); 21 | let foo = ""; 22 | let hello = "world"; 23 | let vector = vec![1, 3, 6]; 24 | ctx.add("foo", &foo); 25 | ctx.add("hello", &hello); 26 | ctx.add("vector", &vector); 27 | template_engine.render("index.tera", ctx).unwrap() 28 | }); 29 | 30 | server.listen("127.0.0.1:6767"); 31 | } 32 | -------------------------------------------------------------------------------- /logging/envlogger/src/simple.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | extern crate env_logger; 4 | 5 | use log::Level; 6 | 7 | 8 | fn level() { 9 | println!("{}, {}, {}, {}, {}", 10 | Level::Trace, Level::Debug, Level::Info, Level::Warn, Level::Error); 11 | } 12 | 13 | fn simple() { 14 | trace!("trace level msg"); // RUST_LOG=trace 15 | debug!("debug level msg"); // RUST_LOG=debug 16 | info!("info level msg"); // RUST_LOG=info 17 | warn!("warn level msg"); // RUST_LOG=warn 18 | error!("error level msg"); // RUST_LOG=error (defaul level) 19 | } 20 | 21 | fn mytarget() { 22 | debug!(target: "mytarget", "debug target msg"); // RUST_LOG=mytarget 23 | warn!(target: "mytarget", "warn target msg"); // RUST_LOG=mytarget=warn 24 | } 25 | 26 | fn main() { 27 | env_logger::init(); 28 | 29 | level(); 30 | simple(); 31 | mytarget(); 32 | 33 | //log::shutdown_logger().expect("shutdown logger error"); 34 | } 35 | -------------------------------------------------------------------------------- /http-client/src/ws-client.rs: -------------------------------------------------------------------------------- 1 | extern crate ws; 2 | extern crate env_logger; 3 | 4 | use ws::{connect, Handler, Sender, Handshake, Result, Message, CloseCode}; 5 | 6 | const WS_URL: &str = "ws://echo.websocket.org"; 7 | const WSS_URL: &str = "wss://echo.websocket.org"; 8 | 9 | struct Client { 10 | out: Sender, 11 | } 12 | 13 | impl Handler for Client { 14 | fn on_open(&mut self, _: Handshake) -> Result<()> { 15 | self.out.send("Hello ws-rs (wss)") 16 | } 17 | 18 | fn on_message(&mut self, msg: Message) -> Result<()> { 19 | println!("recv msg: {}", msg); 20 | self.out.close(CloseCode::Normal) 21 | } 22 | } 23 | 24 | fn main() { 25 | env_logger::init(); 26 | 27 | connect(WS_URL, |out| { 28 | out.send("Hello ws-rs").unwrap(); 29 | 30 | move |msg| { 31 | println!("msg recv: {}", msg); 32 | out.close(CloseCode::Normal) 33 | } 34 | }).expect("fail wss connect"); 35 | 36 | connect(WSS_URL, |out| Client { out: out } ).unwrap() 37 | } 38 | -------------------------------------------------------------------------------- /networking/src/scp.rs: -------------------------------------------------------------------------------- 1 | extern crate networking; 2 | use networking::sshutil; 3 | use std::io::prelude::*; 4 | use std::path::Path; 5 | 6 | static USERNAME: &'static str = "username"; 7 | static REMOTE_ADDRESS: &'static str = "127.0.0.1:22"; 8 | static REMOTE_FILE: &'static str = "/path/to/remote"; 9 | static NEW_REMOTE_FILE: &'static str = "/path/to/remote.new"; 10 | 11 | fn main() { 12 | let (_tcp, session) = sshutil::ssh_login(REMOTE_ADDRESS, USERNAME); 13 | 14 | let (mut remote_file, stat) = session.scp_recv(Path::new(REMOTE_FILE)) 15 | .unwrap(); 16 | println!("remote file stat: {}", stat.size()); 17 | 18 | let mut contents = Vec::new(); 19 | remote_file.read_to_end(&mut contents).unwrap(); 20 | 21 | let mut new_remote_file = session.scp_send(Path::new(NEW_REMOTE_FILE), 22 | 0o644, 23 | stat.size(), 24 | None) 25 | .unwrap(); 26 | new_remote_file.write_all(&contents).unwrap(); 27 | } 28 | -------------------------------------------------------------------------------- /serialize/msgpack_rmp/src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate serde_derive; 3 | 4 | use std::io::Cursor; 5 | 6 | use serde::{Deserialize, Serialize}; 7 | use rmp_serde::{Deserializer, Serializer}; 8 | 9 | #[derive(Debug, PartialEq, Deserialize, Serialize)] 10 | struct Custom { 11 | id: u16, 12 | key: String, 13 | } 14 | 15 | fn main() { 16 | let val = (11, "Hi"); 17 | let mut buf = [0x00; 15]; 18 | let _ = val.serialize(&mut Serializer::new(&mut &mut buf[..])).unwrap(); 19 | println!("encode: {:?}", buf); 20 | 21 | let mut de = Deserializer::new(&buf[..]); 22 | let res: (u8, String) = Deserialize::deserialize(&mut de).unwrap(); 23 | println!("decode: {:?}", res); 24 | 25 | let mut buf = Vec::new(); 26 | let val = Custom { 27 | id: 33, 28 | key: "Hello".into(), 29 | }; 30 | 31 | let _ = val.serialize(&mut Serializer::new(&mut buf)).unwrap(); 32 | println!("encode: {:?}", buf); 33 | 34 | let cur = Cursor::new(&buf[..]); 35 | let mut de = Deserializer::new(cur); 36 | let res: (u16, String) = Deserialize::deserialize(&mut de).unwrap(); 37 | println!("decode: {:?}", res); 38 | } 39 | -------------------------------------------------------------------------------- /databases/rusqlite_sqlite/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate rusqlite; 2 | 3 | use rusqlite::Connection; 4 | 5 | fn main() { 6 | let conn = Connection::open_in_memory().unwrap(); 7 | 8 | conn.execute("CREATE TABLE person ( 9 | id INTEGER PRIMARY KEY, 10 | name TEXT NOT NULL, 11 | age INTEGER NOT NULL, 12 | created TEXT NOT NULL 13 | )", []).unwrap(); 14 | 15 | let name = "rustacean"; 16 | let age = "20"; 17 | conn.execute("INSERT INTO person (name, age, created) 18 | VALUES (?1, ?2, datetime())", 19 | &[&name, &age]).unwrap(); 20 | 21 | let mut stmt = conn.prepare("SELECT id, name, age, created FROM person").unwrap(); 22 | let mut cursor = stmt.query([]).expect("stmt.query() error"); 23 | while let Some(r) = cursor.next().unwrap() { 24 | let id: i32 = r.get(0).unwrap(); 25 | let name: String = r.get(1).unwrap(); 26 | let age: i32 = r.get(2).unwrap(); 27 | let created: String = r.get(3).unwrap(); 28 | println!("{:?}, {}, {}, {}", id, name, age, created); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /networking/src/nix-tfo-client.rs: -------------------------------------------------------------------------------- 1 | extern crate nix; 2 | 3 | use std::net::{IpAddr, Ipv4Addr, SocketAddr}; 4 | use nix::sys::socket::{AddressFamily, InetAddr, SockType, SockFlag, SockAddr, MsgFlags, socket, sendto}; 5 | use nix::unistd::close; 6 | use nix::c_int; 7 | 8 | const MSG_FASTOPEN: c_int = 0x20000000; 9 | 10 | fn main() { 11 | //let protocol = 0; 12 | let protocol = nix::sys::socket::SockLevel::Ip as i32; 13 | let sock = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), protocol).expect("socket() error"); 14 | let stdsockaddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 9999); 15 | let sockaddr = SockAddr::new_inet(InetAddr::from_std(&stdsockaddr)); 16 | let msgflags = MsgFlags::from_bits(MSG_FASTOPEN).expect("invalid msg flags"); 17 | 18 | sendto(sock, b"1. First connection.", &sockaddr, msgflags).expect("sendto(1) error"); 19 | close(sock).unwrap(); 20 | 21 | let sock2 = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(), protocol).expect("socket() error"); 22 | sendto(sock2, b"2. Sending data by using TCP fast open!!!", &sockaddr, msgflags).expect("sendto(2) error"); 23 | 24 | close(sock2).unwrap(); 25 | } 26 | -------------------------------------------------------------------------------- /nickelapp/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "nickelapp" 3 | version = "0.1.0" 4 | authors = ["Hideo Hattori "] 5 | 6 | [dependencies] 7 | mysql = "*" 8 | r2d2 = "0.7" 9 | r2d2_sqlite = "0.0.6" 10 | nickel_mustache = "*" 11 | rustc-serialize = "0.3" 12 | tera = "0.1.3" 13 | redis = "*" 14 | 15 | [dependencies.nickel] 16 | version = "*" 17 | 18 | [dependencies.nickel_mysql] 19 | git = "https://github.com/hhatto/nickel-mysql.git" 20 | 21 | [dependencies.nickel_sqlite] 22 | git = "https://github.com/flosse/nickel-sqlite.git" 23 | 24 | [dependencies.nickel_postgres] 25 | git = "https://github.com/nickel-org/nickel-postgres.git" 26 | 27 | [dependencies.nickel_redis] 28 | git = "https://github.com/matthewbentley/nickel-redis.git" 29 | 30 | [[bin]] 31 | name = "with-mysql" 32 | path = "src/with-mysql.rs" 33 | 34 | [[bin]] 35 | name = "with-sqlite" 36 | path = "src/with-sqlite.rs" 37 | 38 | [[bin]] 39 | name = "with-mustache" 40 | path = "src/with-mustache.rs" 41 | 42 | [[bin]] 43 | name = "with-tera" 44 | path = "src/with-tera.rs" 45 | 46 | [[bin]] 47 | name = "with-postgres" 48 | path = "src/with-postgres.rs" 49 | 50 | [[bin]] 51 | name = "with-redis" 52 | path = "src/with-redis.rs" 53 | -------------------------------------------------------------------------------- /email/src/lettre-use-gmail.rs: -------------------------------------------------------------------------------- 1 | use std::env; 2 | use std::path::Path; 3 | use lettre::{SmtpClient, Transport}; 4 | use lettre::smtp::authentication::Credentials; 5 | use lettre_email::EmailBuilder; 6 | 7 | fn send_mail_via_gmail() { 8 | let host = "smtp.gmail.com"; 9 | let username = env::var("GMAIL_USERNAME").unwrap(); 10 | let password = env::var("GMAIL_PASSWORD").unwrap(); 11 | let creds = Credentials::new(username.to_string(), password); 12 | let mut sender = SmtpClient::new_simple(host) 13 | .unwrap() 14 | .credentials(creds) 15 | .transport(); 16 | 17 | let to_address = "hoge@example.com"; 18 | let cc_address = "huga@example.com"; 19 | let email = EmailBuilder::new() 20 | .to((to_address, "Hogeta Hogeo")) 21 | .from(username) 22 | .cc(cc_address) 23 | .subject("どうもxxです") 24 | .text("こんにちはRust") 25 | .attachment_from_file(Path::new("src/main.rs"), None, &mime::TEXT_PLAIN).expect("attach error") 26 | .build().expect("fail to build email"); 27 | 28 | let result = sender.send(email.into()); 29 | println!("{}", result.is_ok()); 30 | } 31 | 32 | fn main() { 33 | send_mail_via_gmail(); 34 | } 35 | -------------------------------------------------------------------------------- /chan/src/chan.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate chan; 3 | extern crate chan_signal; 4 | 5 | use std::thread; 6 | use std::time::Duration; 7 | use chan_signal::Signal; 8 | 9 | fn run(sdone: chan::Sender<()>) { 10 | println!("running"); 11 | thread::sleep(Duration::from_millis(3000)); 12 | 13 | println!("run.send"); 14 | sdone.send(()); 15 | println!("run.send.end"); 16 | } 17 | 18 | fn main() { 19 | let signal = chan_signal::notify(&[ 20 | Signal::INT, 21 | Signal::TERM, 22 | ]); 23 | let (sdone, rdone) = chan::sync(0); 24 | thread::spawn(move || run(sdone)); 25 | 26 | let tick = chan::tick_ms(1000); 27 | let boom = chan::after_ms(5000); 28 | loop { 29 | chan_select! { 30 | default => { println!("."); thread::sleep(Duration::from_millis(1000)); }, 31 | signal.recv() -> signal => { 32 | println!("signal.recv. sig={:?}", signal); 33 | }, 34 | tick.recv() => println!("tick."), 35 | rdone.recv() => { println!("rdone"); return; }, 36 | boom.recv() => { println!("boom!"); return; }, 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /databases/sqlite_sqlite/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate sqlite; 2 | 3 | use sqlite::Value; 4 | 5 | fn main() { 6 | let conn = sqlite::open(":memory:").expect("sqlite open() error"); 7 | 8 | conn.execute("CREATE TABLE person ( 9 | id INTEGER PRIMARY KEY, 10 | name TEXT NOT NULL, 11 | age INTEGER NOT NULL, 12 | created TEXT NOT NULL 13 | )").expect("create table error."); 14 | 15 | let name = "rustacean"; 16 | let age = 20; 17 | let mut cursor = conn.prepare("INSERT INTO person (name, age, created) 18 | VALUES (?, ?, datetime())" 19 | ).expect("prepare error").cursor(); 20 | cursor.bind(&[Value::String(name.to_string()), 21 | Value::Integer(age) 22 | ]).expect("bind insert error"); 23 | 24 | while let Some(row) = cursor.next().unwrap() { 25 | println!("{:?}", row); 26 | } 27 | 28 | let mut cursor = conn.prepare("SELECT * FROM person").expect("select prepare error").cursor(); 29 | 30 | while let Some(row) = cursor.next().unwrap() { 31 | println!("{:?}", row); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /logging/envlogger/src/myformatter.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate log; 3 | extern crate env_logger; 4 | 5 | use std::io::Write; 6 | use log::LevelFilter; 7 | use env_logger::{Builder, Env}; 8 | use time::format_description::well_known::Rfc3339; 9 | 10 | fn myformat() { 11 | let env = Env::new().filter("RUST_LOG"); 12 | 13 | let mut builder = Builder::from_env(env); 14 | builder.format(|buf, record| { 15 | let ts = buf.timestamp(); 16 | let style = buf.default_level_style(record.level()); 17 | let file = record.file().unwrap(); 18 | let line = record.line().unwrap(); 19 | let now = time::OffsetDateTime::now_utc(); 20 | let n = now.format(&Rfc3339).unwrap(); 21 | writeln!( 22 | buf, 23 | "[{}] [{}:{}] {}({}) {}:{style}{}{style:#}", 24 | record.level(), file, line, n, ts, record.target(), record.args() 25 | ) 26 | }) 27 | // .filter(None, LevelFilter::Debug) 28 | .filter(None, LevelFilter::Info) 29 | .init(); 30 | 31 | debug!("debug level msg"); 32 | info!("info level msg"); 33 | warn!("warn level msg"); 34 | error!("error level msg"); 35 | } 36 | 37 | fn main() { 38 | myformat(); 39 | } 40 | -------------------------------------------------------------------------------- /extension/benchmark/bench.py: -------------------------------------------------------------------------------- 1 | from benchmarker import Benchmarker 2 | import fast_woothee_pyo3 3 | import fast_woothee_cpy 4 | 5 | ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36' 6 | 7 | 8 | n = 1000 * 1000 9 | 10 | with Benchmarker(n) as bench: 11 | 12 | @bench("(rust-cpython) parse") 13 | def _cpython(bm): 14 | parse = fast_woothee_cpy.parse 15 | for i in bm: 16 | parse(ua) 17 | 18 | @bench("(pyo3) parse") 19 | def _pyo3(bm): 20 | parse = fast_woothee_pyo3.parse 21 | for i in bm: 22 | parse(ua) 23 | 24 | @bench("(rust-cpython) parse2") 25 | def _cpython(bm): 26 | parse = fast_woothee_cpy.parse2 27 | for i in bm: 28 | parse(ua) 29 | 30 | @bench("(pyo3) parse2") 31 | def _pyo3(bm): 32 | parse = fast_woothee_pyo3.parse2 33 | for i in bm: 34 | parse(ua) 35 | 36 | @bench("(rust-cpython) is_crawler") 37 | def _cpython(bm): 38 | parse = fast_woothee_cpy.is_crawler 39 | for i in bm: 40 | parse(ua) 41 | 42 | @bench("(pyo3) is_crawler") 43 | def _pyo3(bm): 44 | parse = fast_woothee_pyo3.is_crawler 45 | for i in bm: 46 | parse(ua) 47 | -------------------------------------------------------------------------------- /parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | // #![feature(test)] 2 | // extern crate uap_rust; 3 | // extern crate woothee; 4 | // use uap_rust::parser as uap; 5 | // use woothee::parser as woo; 6 | // 7 | // pub fn b_uap() { 8 | // let parser = uap::Parser::new().unwrap(); 9 | // let _ = 10 | // parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)".to_string()); 11 | // let _ = parser.parse("Twitterbot/1.0".to_string()); 12 | // let _ = 13 | // parser.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)" 14 | // .to_string()); 15 | // } 16 | // 17 | // pub fn b_woothee() { 18 | // let parser = woo::Parser::new(); 19 | // let _ = parser.parse("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"); 20 | // let _ = parser.parse("Twitterbot/1.0"); 21 | // let _ = parser.parse("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)"); 22 | // } 23 | // 24 | // extern crate test; 25 | // use test::Bencher; 26 | // #[bench] 27 | // fn bench_uap(b: &mut Bencher) { 28 | // b.iter(|| b_uap()); 29 | // } 30 | // 31 | // #[bench] 32 | // fn bench_woothee(b: &mut Bencher) { 33 | // b.iter(|| b_woothee()); 34 | // } 35 | // 36 | // #[bench] 37 | // fn bench_stabilizer(b: &mut Bencher) { 38 | // b.iter(|| "hoge".contains("h")); 39 | // } 40 | -------------------------------------------------------------------------------- /http-client/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "http-client" 3 | version = "0.1.0" 4 | authors = ["hhatto "] 5 | edition = "2021" 6 | 7 | [dependencies] 8 | hyper = { version = "0.14", features = ["full"] } 9 | hyper-tls = "0.5" 10 | tokio = { version = "1", features = ["full"] } 11 | http = "0.2" 12 | native-tls = "0.2.10" 13 | tokio-tls = "0.3" 14 | rustc-serialize = "0.3" 15 | serde = "1" 16 | serde_json = "1" 17 | solicit = "0.4" 18 | websocket = "0.26.5" 19 | h2 = "0.3" 20 | futures = "0.1" 21 | rustls = "0.20" 22 | tokio-rustls = "0.23" 23 | webpki = "0.22" 24 | webpki-roots = "*" 25 | env_logger = "0.5.4" 26 | 27 | [dependencies.ws] 28 | version = "0.9" 29 | 30 | [dependencies.url] 31 | git = "https://github.com/servo/rust-url" 32 | 33 | [[bin]] 34 | name = "get-json-hyper" 35 | path = "src/get-json-hyper.rs" 36 | 37 | [[bin]] 38 | name = "http-hyper" 39 | path = "src/http-hyper.rs" 40 | 41 | [[bin]] 42 | name = "http2-hyper" 43 | path = "src/http2-hyper.rs" 44 | 45 | [[bin]] 46 | name = "http2-solicit" 47 | path = "src/http2-solicit.rs" 48 | 49 | [[bin]] 50 | name = "url" 51 | path = "src/url.rs" 52 | 53 | [[bin]] 54 | name = "rust-websocket" 55 | path = "src/rust-websocket.rs" 56 | 57 | [[bin]] 58 | name = "rust-websocket-server" 59 | path = "src/rust-websocket-server.rs" 60 | 61 | [[bin]] 62 | name = "ws-client" 63 | path = "src/ws-client.rs" 64 | -------------------------------------------------------------------------------- /regex/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | extern crate regex; 4 | 5 | use regex::Regex; 6 | 7 | pub fn number_literal() { 8 | let text = r#"print("hoge")\n# this is comment\na = 1\na += 2"#; 9 | let re = Regex::new(r"(0x[0-9a-fA-F]([0-9a-fA-F]|\.)*|\d(\d|\.)*)([uU][lL]{0,2}|([eE][-+]\d*)?[fFlL]*)") 10 | .unwrap(); 11 | re.find(text); 12 | } 13 | 14 | pub fn number_literal_match() { 15 | let text = r#"print("hoge")\n# this is comment\na = 1\na += 2"#; 16 | let re = Regex::new(r"^(0x[0-9a-fA-F]([0-9a-fA-F]|\.)*|\d(\d|\.)*)([uU][lL]{0,2}|([eE][-+]\d*)?[fFlL]*)") 17 | .unwrap(); 18 | re.find(text); 19 | } 20 | 21 | pub fn number_literal_match2() { 22 | let text = r#"print("hoge")\n# this is comment\na = 1\na += 2"#; 23 | let re = Regex::new(r"^((0x[0-9a-fA-F]([0-9a-fA-F]|\.)*|\d(\d|\.)*)([uU][lL]{0,2}|([eE][-+]\d*)?[fFlL]*))") 24 | .unwrap(); 25 | re.find(text); 26 | } 27 | 28 | #[cfg(test)] 29 | mod tests { 30 | use super::*; 31 | use test::Bencher; 32 | 33 | #[bench] 34 | fn bench_num_search(b: &mut Bencher) { 35 | b.iter(|| number_literal()); 36 | } 37 | 38 | #[bench] 39 | fn bench_num_match(b: &mut Bencher) { 40 | b.iter(|| number_literal_match()); 41 | } 42 | 43 | #[bench] 44 | fn bench_num_match2(b: &mut Bencher) { 45 | b.iter(|| number_literal_match2()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /serialize/xml/src/xmlrs.rs: -------------------------------------------------------------------------------- 1 | extern crate xml; 2 | 3 | use xml::reader::{EventReader, XmlEvent}; 4 | 5 | fn main() { 6 | let xml = r#" 7 | 8 | 9 | 10 | 9 11 | 12 | 10 13 | description 14 | 15 | 16 | 17 | 18 | 1502953063279 19 | 20 | 21 | "#; 22 | 23 | let reader = EventReader::from_str(xml); 24 | 25 | for e in reader { 26 | match e { 27 | Ok(XmlEvent::StartElement { name, attributes, .. }) => { 28 | println!("tag-name: {:?} attr: {:?}", 29 | name.local_name, 30 | attributes.into_iter().map(|a| { 31 | format!("{}={}", a.name.local_name, a.value) 32 | }).collect::>()); 33 | }, 34 | Ok(XmlEvent::EndElement { .. }) => { 35 | //println!("tag-name(e): {:?}", name); 36 | } 37 | Ok(XmlEvent::Characters(s)) => println!(" text: {}", s), 38 | Err(e) => panic!("error: {:?}", e), 39 | _ => (), 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /chan/src/chan-mpmc.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate chan; 3 | 4 | use std::thread; 5 | use std::time::Duration; 6 | 7 | fn producer(sdone: chan::Sender) { 8 | println!("start producer"); 9 | 10 | for i in 0..10 { 11 | println!("run.send. i={:?}", i); 12 | sdone.send(i); 13 | thread::sleep(Duration::from_millis(100)); 14 | } 15 | println!("end producer"); 16 | } 17 | 18 | fn consumer(id: i32, rdone: chan::Receiver) { 19 | println!("start consumer {}", id); 20 | 21 | loop { 22 | chan_select! { 23 | rdone.recv() -> ret => { 24 | match ret { 25 | None => break, 26 | Some(v) => println!("id={}, recv. ret={:?}", id, v), 27 | } 28 | } 29 | } 30 | } 31 | 32 | println!("end consumer {}", id); 33 | } 34 | 35 | fn main() { 36 | let (sdone, rdone) = chan::sync(0); 37 | thread::spawn(move || producer(sdone)); 38 | for id in 0..2 { 39 | let crdone = rdone.clone(); 40 | thread::spawn(move || consumer(id, crdone)); 41 | } 42 | 43 | let tick = chan::tick_ms(1000); 44 | let boom = chan::after_ms(5000); 45 | loop { 46 | chan_select! { 47 | default => { println!("."); thread::sleep(Duration::from_millis(1000)); }, 48 | tick.recv() => println!("tick."), 49 | boom.recv() => break, 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /nickelapp/src/with-mysql.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nickel; 3 | extern crate mysql; 4 | extern crate nickel_mysql; 5 | 6 | use nickel::{Nickel, HttpRouter}; 7 | use nickel_mysql::{MysqlMiddleware, MysqlRequestExtensions}; 8 | use mysql::value::from_value; 9 | 10 | const DB_NAME: &'static str = "database"; 11 | const DB_USER: &'static str = "user"; 12 | const DB_PASS: &'static str = "pass"; 13 | 14 | struct Purin { 15 | id: u32, 16 | name: String, 17 | } 18 | 19 | fn main() { 20 | let mut server = Nickel::new(); 21 | 22 | server.utilize(router! { 23 | get "**" => |_req, _res| { 24 | "Hello world!" 25 | } 26 | }); 27 | 28 | server.utilize(MysqlMiddleware::new(DB_NAME, DB_USER, DB_PASS)); 29 | 30 | server.get("/test", 31 | middleware! { |request| 32 | let db_conn = request.db_connection(); 33 | let players: Vec = db_conn.prep_exec("SELECT id, name FROM purin", ()).map(|result| { 34 | result.map(|x| x.unwrap()).map(|mut row| { 35 | Purin { 36 | id: from_value(row.take("id").unwrap()), 37 | name: from_value(row.take("name").unwrap()), 38 | } 39 | }).collect() 40 | }).unwrap(); 41 | 42 | for p in players.iter() { 43 | println!("id: {}, name: {}", p.id, p.name); 44 | } 45 | }); 46 | 47 | server.listen("127.0.0.1:6767"); 48 | } 49 | -------------------------------------------------------------------------------- /http-client/src/get-json-hyper.rs: -------------------------------------------------------------------------------- 1 | use std::io::Read; 2 | use rustc_serialize::json::Json; 3 | use hyper::Client; 4 | use hyper::body::Buf; 5 | use hyper_tls::HttpsConnector; 6 | 7 | static REQUEST_URL: &'static str = "https://qiita.com/api/v2/items?per_page=2"; 8 | 9 | pub fn parse_json(jsonstr: &String) { 10 | let data = Json::from_str(&jsonstr).unwrap(); 11 | let items = data.as_array().unwrap(); 12 | 13 | for d in items.iter() { 14 | let item = d.as_object().unwrap().get("title").unwrap(); 15 | let datetime = d.as_object().unwrap().get("updated_at").unwrap(); 16 | println!("{} {}", 17 | match *datetime { 18 | Json::String(ref v) => format!("{}", v), 19 | _ => format!(""), 20 | }, 21 | match *item { 22 | Json::String(ref v) => format!("{}", v), 23 | _ => format!(""), 24 | }); 25 | } 26 | } 27 | 28 | #[tokio::main] 29 | async fn main() -> Result<(), Box> { 30 | let https = HttpsConnector::new(); 31 | let client = Client::builder().build::<_, hyper::Body>(https); 32 | let url = REQUEST_URL.parse()?; 33 | 34 | let res = client.get(url).await?; 35 | let body = hyper::body::aggregate(res).await?; 36 | 37 | let mut bbody = String::new(); 38 | match body.reader().read_to_string(&mut bbody) { 39 | Ok(_) => parse_json(&bbody), 40 | Err(e) => println!("error: {}", e), 41 | }; 42 | 43 | Ok(()) 44 | } 45 | -------------------------------------------------------------------------------- /serialize/yaml/src/parse-yaml.rs: -------------------------------------------------------------------------------- 1 | extern crate yaml_rust; 2 | use yaml_rust::YamlLoader; 3 | use std::io::prelude::*; 4 | use std::error::Error; 5 | use std::fs::File; 6 | use std::path::Path; 7 | 8 | fn parse_yaml(yamlstr: &String) { 9 | let docs = YamlLoader::load_from_str(yamlstr).unwrap(); 10 | let doc = &docs[0]; 11 | 12 | let bad = &doc["domain"]; 13 | if !bad.is_badvalue() { 14 | println!("{}", bad.as_str().unwrap()); 15 | } 16 | 17 | let paths = &doc["paths"]; 18 | if !paths.is_badvalue() { 19 | let pathvec = paths.as_vec().unwrap(); 20 | for path in pathvec { 21 | for (key, value) in path.as_hash().unwrap() { 22 | println!("{:?} {}: {}", 23 | path, 24 | key.as_str().unwrap(), 25 | value.as_str().unwrap()); 26 | } 27 | } 28 | } 29 | } 30 | 31 | fn main() { 32 | if std::env::args().len() != 2 { 33 | println!("usage: PROG FILE.yaml"); 34 | return; 35 | } 36 | let yamlfile = std::env::args().last().unwrap(); 37 | let path = Path::new(&yamlfile); 38 | let display = path.display(); 39 | 40 | let mut f = match File::open(&path) { 41 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 42 | Ok(file) => file, 43 | }; 44 | 45 | let mut s = String::new(); 46 | match f.read_to_string(&mut s) { 47 | Err(why) => panic!("could not read {}: {}", display, Error::description(&why)), 48 | Ok(_) => parse_yaml(&s), 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /extension/pyo3/src/cpy.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate cpython; 3 | extern crate woothee; 4 | 5 | use std::collections::HashMap; 6 | use cpython::{PyDict, PyErr, PyResult, Python}; 7 | use woothee::parser::{Parser, WootheeResult}; 8 | 9 | py_exception!(fast_woothee, ExtParseError); 10 | 11 | py_module_initializer!(fast_woothee, initfast_woothee, PyInit_fast_woothee, |py, m| { 12 | m.add(py, "is_crawler", py_fn!(py, is_crawler(agent: &str)))?; 13 | m.add(py, "parse", py_fn!(py, parse(agent: &str)))?; 14 | Ok(()) 15 | }); 16 | 17 | pub fn parse(py: Python, agent: &str) -> PyResult> { 18 | let parser = Parser::new(); 19 | let result = parser.parse(agent); 20 | let r = match result { 21 | Some(r) => r, 22 | None => WootheeResult::new(), 23 | }; 24 | let mut h = HashMap::new(); 25 | h.insert("name".to_string(), r.name.to_owned()); 26 | h.insert("category".to_string(), r.category.to_string()); 27 | h.insert("os".to_string(), r.os.to_string()); 28 | h.insert("os_version".to_string(), r.os_version.to_string()); 29 | h.insert("browser_type".to_string(), r.browser_type.to_string()); 30 | h.insert("version".to_string(), r.version.to_string()); 31 | h.insert("vendor".to_string(), r.vendor.to_string()); 32 | Ok(h) 33 | } 34 | 35 | pub fn is_crawler(_: Python, agent: &str) -> PyResult { 36 | if agent.is_empty() || agent == "-" { 37 | return Ok(false); 38 | } 39 | 40 | let parser = Parser::new(); 41 | let mut result = WootheeResult::new(); 42 | Ok(parser.try_crawler(agent, &mut result)) 43 | } 44 | -------------------------------------------------------------------------------- /nickelapp/src/with-sqlite.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nickel; 3 | extern crate r2d2; 4 | extern crate nickel_sqlite; 5 | extern crate r2d2_sqlite; 6 | 7 | use nickel::{Nickel, HttpRouter}; 8 | use nickel_sqlite::{SqliteMiddleware, SqliteRequestExtensions}; 9 | 10 | const DB_FILE: &'static str = "purin.sqlite"; 11 | 12 | const CRATE_TABLE: &'static str = " 13 | CREATE TABLE purin ( 14 | id INTEGER PRIMARY KEY, 15 | name TEXT NOT NULL 16 | )"; 17 | 18 | struct Purin { 19 | id: i32, 20 | name: String, 21 | } 22 | 23 | fn main() { 24 | let mut server = Nickel::new(); 25 | 26 | let mw = SqliteMiddleware::new(DB_FILE).expect("Unable to connect to database"); 27 | let db = mw.pool.clone().get().unwrap(); 28 | 29 | match db.execute(CRATE_TABLE, &[]) { 30 | Ok(_) => println!("create table"), 31 | Err(_) => {} 32 | }; 33 | 34 | server.utilize(mw); 35 | 36 | server.utilize(router! { 37 | get "**" => |_req, _res| { 38 | "Hello world!" 39 | } 40 | }); 41 | 42 | server.get("/test", 43 | middleware! { |request| 44 | let db_conn = request.db_conn().unwrap(); 45 | let mut stmt = db_conn.prepare("SELECT id, name FROM purin").unwrap(); 46 | let players = stmt.query_map(&[], |row| { 47 | Purin { 48 | id: row.get(0), 49 | name: row.get(1), 50 | } 51 | }).unwrap(); 52 | 53 | for player in players { 54 | let p = player.unwrap(); 55 | println!("id: {}, name: {}", p.id, p.name); 56 | } 57 | }); 58 | 59 | server.listen("127.0.0.1:6767"); 60 | } 61 | -------------------------------------------------------------------------------- /serialize/xml/src/quickxml.rs: -------------------------------------------------------------------------------- 1 | extern crate quick_xml; 2 | 3 | use quick_xml::reader::Reader; 4 | use quick_xml::events::Event; 5 | 6 | fn main() { 7 | let xml = r#" 8 | 9 | 10 | 11 | 9 12 | 13 | 10 14 | description 15 | 16 | 17 | 18 | 19 | 1502953063279 20 | 21 | 22 | "#; 23 | 24 | let mut buf = Vec::new(); 25 | let mut reader = Reader::from_str(xml); 26 | reader.trim_text(true); 27 | 28 | loop { 29 | match reader.read_event_into(&mut buf) { 30 | Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e)) => { 31 | println!("tag-name: {:?} attr: {:?}", std::str::from_utf8(e.name().as_ref()).expect("convert error"), 32 | e.attributes().map(|a| { 33 | let v = a.unwrap(); 34 | format!("{}={}", 35 | std::str::from_utf8(v.key.as_ref()).expect("convert error"), 36 | std::str::from_utf8(v.value.as_ref()).expect("convert error")) 37 | }).collect::>()); 38 | }, 39 | Ok(Event::Text(e)) => println!(" text: {}", e.unescape().unwrap()), 40 | Ok(Event::Eof) => break, 41 | Err(e) => panic!("error: {}: {:?}", reader.buffer_position(), e), 42 | _ => (), 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /databases/sqlite_sqlite/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "cc" 7 | version = "1.0.73" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" 10 | 11 | [[package]] 12 | name = "libc" 13 | version = "0.2.126" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" 16 | 17 | [[package]] 18 | name = "pkg-config" 19 | version = "0.3.25" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" 22 | 23 | [[package]] 24 | name = "sqlite" 25 | version = "0.26.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "3fb1a534c07ec276fbbe0e55a1c00814d8563da3a2f4d9d9d4c802bd1278db6a" 28 | dependencies = [ 29 | "libc", 30 | "sqlite3-sys", 31 | ] 32 | 33 | [[package]] 34 | name = "sqlite3-src" 35 | version = "0.3.0" 36 | source = "registry+https://github.com/rust-lang/crates.io-index" 37 | checksum = "a260b07ce75a0644c6f5891f34f46db9869e731838e95293469ab17999abcfa3" 38 | dependencies = [ 39 | "cc", 40 | "pkg-config", 41 | ] 42 | 43 | [[package]] 44 | name = "sqlite3-sys" 45 | version = "0.13.0" 46 | source = "registry+https://github.com/rust-lang/crates.io-index" 47 | checksum = "04d2f028faeb14352df7934b4771806f60d61ce61be1928ec92396d7492e2e54" 48 | dependencies = [ 49 | "libc", 50 | "sqlite3-src", 51 | ] 52 | 53 | [[package]] 54 | name = "sqlite_sqlite" 55 | version = "0.1.0" 56 | dependencies = [ 57 | "sqlite", 58 | ] 59 | -------------------------------------------------------------------------------- /dotenv/dotenvy/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "dotenv" 7 | version = "0.1.0" 8 | dependencies = [ 9 | "dotenvy", 10 | "dotenvy_macro", 11 | ] 12 | 13 | [[package]] 14 | name = "dotenvy" 15 | version = "0.15.7" 16 | source = "registry+https://github.com/rust-lang/crates.io-index" 17 | checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" 18 | 19 | [[package]] 20 | name = "dotenvy_macro" 21 | version = "0.15.7" 22 | source = "registry+https://github.com/rust-lang/crates.io-index" 23 | checksum = "cb0235d912a8c749f4e0c9f18ca253b4c28cfefc1d2518096016d6e3230b6424" 24 | dependencies = [ 25 | "dotenvy", 26 | "proc-macro2", 27 | "quote", 28 | "syn", 29 | ] 30 | 31 | [[package]] 32 | name = "proc-macro2" 33 | version = "1.0.83" 34 | source = "registry+https://github.com/rust-lang/crates.io-index" 35 | checksum = "0b33eb56c327dec362a9e55b3ad14f9d2f0904fb5a5b03b513ab5465399e9f43" 36 | dependencies = [ 37 | "unicode-ident", 38 | ] 39 | 40 | [[package]] 41 | name = "quote" 42 | version = "1.0.36" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" 45 | dependencies = [ 46 | "proc-macro2", 47 | ] 48 | 49 | [[package]] 50 | name = "syn" 51 | version = "1.0.109" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 54 | dependencies = [ 55 | "proc-macro2", 56 | "quote", 57 | "unicode-ident", 58 | ] 59 | 60 | [[package]] 61 | name = "unicode-ident" 62 | version = "1.0.12" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 65 | -------------------------------------------------------------------------------- /parse-cmdline-option/src/cat-docopt.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate serde; 3 | extern crate docopt; 4 | use docopt::Docopt; 5 | use std::io::BufReader; 6 | use std::io::prelude::*; 7 | use std::error::Error; 8 | use std::fs::File; 9 | use std::path::Path; 10 | 11 | static USAGE: &'static str = " 12 | cat 13 | 14 | Usage: 15 | cat-docopt [-n] [-b] [...] 16 | 17 | Options: 18 | -b Number the non-blank output lines, starting at 1. 19 | -n Number the output lines, starting at 1. 20 | "; 21 | 22 | #[derive(Debug, Deserialize)] 23 | struct Args { 24 | flag_b: bool, 25 | flag_n: bool, 26 | arg_file: Vec, 27 | } 28 | 29 | fn print_lines(path: &Path, opt: &Args) { 30 | let display = path.display(); 31 | let f = match File::open(&path) { 32 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 33 | Ok(file) => file, 34 | }; 35 | 36 | let buf = BufReader::new(&f); 37 | let mut n = 1; 38 | for line in buf.lines() { 39 | match line { 40 | Ok(l) => { 41 | if opt.flag_b && l == "".to_string() { 42 | println!(""); 43 | continue; 44 | } 45 | 46 | if opt.flag_n || opt.flag_b { 47 | println!(" {:5} {}", n, l); 48 | } else { 49 | println!("{}", l); 50 | } 51 | } 52 | Err(_) => {} 53 | }; 54 | n += 1; 55 | } 56 | } 57 | 58 | fn main() { 59 | let args: Args = Docopt::new(USAGE) 60 | .and_then(|d| d.deserialize()) 61 | .unwrap_or_else(|e| e.exit()); 62 | 63 | for arg in &args.arg_file { 64 | let path = Path::new(&arg); 65 | 66 | print_lines(&path, &args); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /parse-cmdline-option/src/cat-argparse.rs: -------------------------------------------------------------------------------- 1 | extern crate argparse; 2 | use argparse::{ArgumentParser, StoreTrue, List}; 3 | use std::io::BufReader; 4 | use std::io::prelude::*; 5 | use std::error::Error; 6 | use std::fs::File; 7 | use std::path::Path; 8 | 9 | struct MyOptions { 10 | print_number: bool, 11 | skip_blank: bool, 12 | } 13 | 14 | fn print_lines(path: &Path, opt: &MyOptions) { 15 | let display = path.display(); 16 | let f = match File::open(&path) { 17 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 18 | Ok(file) => file, 19 | }; 20 | 21 | let buf = BufReader::new(&f); 22 | let mut n = 1; 23 | for line in buf.lines() { 24 | match line { 25 | Ok(l) => { 26 | if opt.skip_blank && l == "".to_string() { 27 | println!(""); 28 | continue; 29 | } 30 | 31 | if opt.print_number || opt.skip_blank { 32 | println!(" {:5} {}", n, l); 33 | } else { 34 | println!("{}", l); 35 | } 36 | } 37 | Err(_) => {} 38 | }; 39 | n += 1; 40 | } 41 | } 42 | 43 | fn main() { 44 | let mut files: Vec = vec![]; 45 | let mut opt = MyOptions { 46 | print_number: false, 47 | skip_blank: false, 48 | }; 49 | 50 | { 51 | let mut parser = ArgumentParser::new(); 52 | parser.set_description("cat"); 53 | parser.refer(&mut opt.print_number) 54 | .add_option(&["-n"], StoreTrue, "Number the output lines, starting at 1."); 55 | parser.refer(&mut opt.skip_blank) 56 | .add_option(&["-b"], StoreTrue, "Number the non-blank output lines, starting at 1."); 57 | parser.refer(&mut files) 58 | .add_argument("file", List, "some files"); 59 | parser.parse_args_or_exit(); 60 | } 61 | 62 | for file in files { 63 | let path = Path::new(&file); 64 | print_lines(&path, &opt); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /parse-cmdline-option/src/cat-getopts.rs: -------------------------------------------------------------------------------- 1 | extern crate getopts; 2 | use getopts::Options; 3 | use std::io::BufReader; 4 | use std::io::prelude::*; 5 | use std::env; 6 | use std::error::Error; 7 | use std::fs::File; 8 | use std::path::Path; 9 | 10 | struct MyOptions { 11 | print_number: bool, 12 | skip_blank: bool, 13 | } 14 | 15 | fn print_lines(path: &Path, opt: &MyOptions) { 16 | let display = path.display(); 17 | let f = match File::open(&path) { 18 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 19 | Ok(file) => file, 20 | }; 21 | 22 | let buf = BufReader::new(&f); 23 | let mut n = 1; 24 | for line in buf.lines() { 25 | match line { 26 | Ok(l) => { 27 | if opt.skip_blank && l == "".to_string() { 28 | println!(""); 29 | continue; 30 | } 31 | 32 | if opt.print_number || opt.skip_blank { 33 | println!(" {:5} {}", n, l); 34 | } else { 35 | println!("{}", l); 36 | } 37 | } 38 | Err(_) => {} 39 | }; 40 | n += 1; 41 | } 42 | } 43 | 44 | fn main() { 45 | let mut opt = MyOptions { 46 | print_number: false, 47 | skip_blank: false, 48 | }; 49 | let args: Vec = env::args().collect(); 50 | 51 | let mut opts = Options::new(); 52 | opts.optflag("n", "", "Number the output lines, starting at 1."); 53 | opts.optflag("b", "", "Number the non-blank output lines, starting at 1."); 54 | let matches = match opts.parse(&args[1..]) { 55 | Ok(m) => m, 56 | Err(_) => { 57 | print!("{}", opts.usage("Usage: cat [options] [FILE]")); 58 | return; 59 | } 60 | }; 61 | 62 | opt.print_number = matches.opt_present("n"); 63 | opt.skip_blank = matches.opt_present("b"); 64 | 65 | let files = matches.free; 66 | 67 | for arg in files { 68 | let path = Path::new(&arg); 69 | 70 | print_lines(&path, &opt); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /microbench/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | 3 | extern crate test; 4 | 5 | use std::collections::HashMap; 6 | 7 | pub fn create_hashmap_with_insert() { 8 | let mut h: HashMap = HashMap::new(); 9 | h.insert("hello1".to_string(), "world1".to_string()); 10 | h.insert("hello2".to_string(), "world2".to_string()); 11 | h.insert("hello3".to_string(), "world3".to_string()); 12 | h.insert("hello4".to_string(), "world4".to_string()); 13 | h.insert("hello5".to_string(), "world5".to_string()); 14 | } 15 | 16 | pub fn create_hashmap_with_tuple_collect() { 17 | let mut h: HashMap = vec![ 18 | ("hello1", "world1"), 19 | ("hello2", "world2"), 20 | ("hello3", "world3"), 21 | ("hello4", "world4"), 22 | ("hello5", "world5"), 23 | ] 24 | .into_iter() 25 | .map(|(k, v)| (k.to_string(), v.to_string())) 26 | .collect::>(); 27 | } 28 | 29 | pub fn create_hashmap_with_tuple_cloned_collect() { 30 | let mut h: HashMap = [("hello1".to_string(), "world1".to_string()), 31 | ("hello2".to_string(), "world2".to_string()), 32 | ("hello3".to_string(), "world3".to_string()), 33 | ("hello4".to_string(), "world4".to_string()), 34 | ("hello5".to_string(), "world5".to_string())] 35 | .iter() 36 | .cloned() 37 | .collect(); 38 | } 39 | 40 | #[cfg(test)] 41 | mod tests { 42 | use super::*; 43 | use test::Bencher; 44 | 45 | #[bench] 46 | fn bench_create_hashmap_with_insert(b: &mut Bencher) { 47 | b.iter(|| create_hashmap_with_insert()); 48 | } 49 | 50 | #[bench] 51 | fn bench_create_hashmap_with_tuple_collect(b: &mut Bencher) { 52 | b.iter(|| create_hashmap_with_tuple_collect()); 53 | } 54 | 55 | #[bench] 56 | fn bench_create_hashmap_with_tuple_cloned_collect(b: &mut Bencher) { 57 | b.iter(|| create_hashmap_with_tuple_cloned_collect()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /mio/src/uds-client.rs: -------------------------------------------------------------------------------- 1 | extern crate mio; 2 | extern crate bytes; 3 | 4 | use std::env; 5 | use std::path::Path; 6 | use mio::*; 7 | use mio::unix::UnixStream; 8 | 9 | const SERVER: Token = Token(0); 10 | const CLIENT: Token = Token(1); 11 | 12 | struct TestHandler { 13 | client: UnixStream, 14 | } 15 | 16 | impl TestHandler { 17 | fn new(cli: UnixStream) -> TestHandler { 18 | TestHandler { client: cli } 19 | } 20 | 21 | fn handle_read(&mut self, _: &mut EventLoop, token: Token, _: EventSet) { 22 | match token { 23 | SERVER => {} 24 | CLIENT => {} 25 | _ => panic!("unexpected token"), 26 | } 27 | } 28 | 29 | fn handle_write(&mut self, event_loop: &mut EventLoop, _: Token, _: EventSet) { 30 | assert!(5 == self.client.try_write(&mut "hello".as_bytes()).unwrap().unwrap()); 31 | event_loop.deregister(&self.client).unwrap(); 32 | event_loop.timeout_ms(1, 200).unwrap(); 33 | } 34 | } 35 | 36 | impl Handler for TestHandler { 37 | type Timeout = usize; 38 | type Message = (); 39 | 40 | fn ready(&mut self, event_loop: &mut EventLoop, token: Token, events: EventSet) { 41 | if events.is_readable() { 42 | self.handle_read(event_loop, token, events); 43 | } 44 | 45 | if events.is_writable() { 46 | self.handle_write(event_loop, token, events); 47 | } 48 | } 49 | 50 | fn timeout(&mut self, event_loop: &mut EventLoop, _: usize) { 51 | event_loop.shutdown(); 52 | } 53 | } 54 | 55 | fn main() { 56 | let socket_path = env::args().skip(1).next().unwrap(); 57 | let mut event_loop = EventLoop::new().unwrap(); 58 | let addr = Path::new(socket_path.as_str()); 59 | let client = UnixStream::connect(&addr).unwrap(); 60 | println!("connect"); 61 | 62 | event_loop.register(&client, CLIENT, EventSet::writable(), PollOpt::level()) 63 | .unwrap(); 64 | 65 | let mut handler = TestHandler::new(client); 66 | event_loop.run(&mut handler).unwrap(); 67 | println!("run.end"); 68 | } 69 | -------------------------------------------------------------------------------- /parse-cmdline-option/src/cat-clap.rs: -------------------------------------------------------------------------------- 1 | extern crate clap; 2 | use std::io::BufReader; 3 | use std::io::prelude::*; 4 | use std::error::Error; 5 | use std::fs::File; 6 | use std::path::Path; 7 | use clap::{App, Arg}; 8 | 9 | struct MyOptions { 10 | print_number: bool, 11 | skip_blank: bool, 12 | } 13 | 14 | fn print_lines(path: &Path, opt: &MyOptions) { 15 | let display = path.display(); 16 | let f = match File::open(&path) { 17 | Err(why) => panic!("could not open {}: {}", display, Error::description(&why)), 18 | Ok(file) => file, 19 | }; 20 | 21 | let buf = BufReader::new(&f); 22 | let mut n = 1; 23 | for line in buf.lines() { 24 | match line { 25 | Ok(l) => { 26 | if opt.skip_blank && l.is_empty() { 27 | println!(""); 28 | continue; 29 | } 30 | 31 | if opt.print_number || opt.skip_blank { 32 | println!(" {:5} {}", n, l); 33 | } else { 34 | println!("{}", l); 35 | } 36 | } 37 | Err(_) => {} 38 | }; 39 | n += 1; 40 | } 41 | } 42 | fn main() { 43 | let mut opt = MyOptions { 44 | print_number: false, 45 | skip_blank: false, 46 | }; 47 | let mut app = App::new("cat") 48 | .version("v0.1") 49 | .arg(Arg::with_name("number") 50 | .short("n") 51 | .help("Number the output lines, starting at 1.")) 52 | .arg(Arg::with_name("blank") 53 | .short("b") 54 | .help("Number the non-blank output lines, starting at 1.")) 55 | .arg(Arg::with_name("files") 56 | .help("some files") 57 | .index(1) 58 | .multiple(true) 59 | .takes_value(true)); 60 | let matches = app.clone().get_matches(); 61 | if matches.values_of("files").is_none() { 62 | let _ = app.print_help(); 63 | println!(""); 64 | return; 65 | } 66 | let files = matches.values_of("files").unwrap(); 67 | match matches.occurrences_of("number") { 68 | 1 => opt.print_number = true, 69 | _ => {} 70 | } 71 | match matches.occurrences_of("blank") { 72 | 1 => opt.skip_blank = true, 73 | _ => {} 74 | } 75 | for file in files { 76 | let path = Path::new(&file); 77 | print_lines(&path, &opt); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /http-client/src/rust-websocket-server.rs: -------------------------------------------------------------------------------- 1 | extern crate websocket; 2 | use std::thread; 3 | use websocket::sync::Server; 4 | use websocket::OwnedMessage; 5 | use websocket::result::WebSocketError; 6 | 7 | fn main() { 8 | let server = Server::bind("127.0.0.1:9999").unwrap(); 9 | 10 | for request in server.filter_map(Result::ok) { 11 | thread::spawn(move || { 12 | if !request.protocols().contains(&("rust-websocket".to_string())) { 13 | request.reject().expect("fail request reject()"); 14 | return; 15 | } 16 | 17 | let client = request.accept().expect("fail accept"); 18 | let ip = client.peer_addr().expect("fail peer_addr()"); 19 | println!("Connection from {}", ip); 20 | 21 | let (mut receiver, mut sender) = client.split().expect("fail client.split()"); 22 | 23 | let mut cnt: i32 = 0; 24 | for msg in receiver.incoming_messages() { 25 | cnt += 1; 26 | let msg: OwnedMessage = match msg { 27 | Ok(m) => m, 28 | Err(WebSocketError::NoDataAvailable) => return, // connection close by client 29 | Err(e) => { 30 | println!("Receive error: {:?}", e); 31 | return; 32 | } 33 | }; 34 | 35 | match msg { 36 | OwnedMessage::Close(_) => { 37 | let msg = OwnedMessage::Close(None); 38 | sender.send_message(&msg).unwrap(); 39 | println!("Client {} disconnected", ip); 40 | return; 41 | } 42 | OwnedMessage::Ping(ping) => { 43 | let msg = OwnedMessage::Pong(ping); 44 | sender.send_message(&msg).unwrap(); 45 | } 46 | OwnedMessage::Pong(_) => { 47 | println!("recv PONG"); 48 | } 49 | _ => { 50 | sender.send_message(&msg).unwrap(); 51 | println!("receive msg: echo: {:?}", msg); 52 | 53 | if cnt % 2 == 1 { 54 | let d = Vec::new(); 55 | sender.send_message(&OwnedMessage::Ping(d)).unwrap(); 56 | println!("send PING"); 57 | } 58 | } 59 | } 60 | } 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /extension/cpython/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate cpython; 3 | extern crate woothee; 4 | 5 | use std::collections::HashMap; 6 | use cpython::{PyResult, Python, PyDict, PyString, PythonObject, PyObject}; 7 | use woothee::parser::{Parser, WootheeResult}; 8 | 9 | py_exception!(fast_woothee, ExtParseError); 10 | 11 | py_module_initializer!(fast_woothee_cpy, initfast_woothee_cpy, PyInit_fast_woothee_cpy, |py, m| { 12 | m.add(py, "is_crawler", py_fn!(py, is_crawler(agent: &str)))?; 13 | m.add(py, "parse", py_fn!(py, parse(agent: &str)))?; 14 | m.add(py, "parse2", py_fn!(py, parse2(agent: &str)))?; 15 | Ok(()) 16 | }); 17 | 18 | pub fn parse(_py: Python, agent: &str) -> PyResult> { 19 | let parser = Parser::new(); 20 | let result = parser.parse(agent); 21 | let r = match result { 22 | Some(r) => r, 23 | None => WootheeResult::new(), 24 | }; 25 | let mut h = HashMap::new(); 26 | h.insert("name".to_string(), r.name.to_string()); 27 | h.insert("category".to_string(), r.category.to_string()); 28 | h.insert("os".to_string(), r.os.to_string()); 29 | h.insert("os_version".to_string(), r.os_version.to_string()); 30 | h.insert("browser_type".to_string(), r.browser_type.to_string()); 31 | h.insert("version".to_string(), r.version.to_string()); 32 | h.insert("vendor".to_string(), r.vendor.to_string()); 33 | Ok(h) 34 | } 35 | 36 | pub fn parse2(py: Python, agent: &str) -> PyResult { 37 | let parser = Parser::new(); 38 | let result = parser.parse(agent); 39 | let r = match result { 40 | Some(r) => r, 41 | None => WootheeResult::new(), 42 | }; 43 | let h = PyDict::new(py); 44 | _ = h.set_item(py, PyString::new(py, "name").into_object(), PyString::new(py, r.name).into_object()); 45 | _ = h.set_item(py, PyString::new(py, "category").into_object(), PyString::new(py, r.category).into_object()); 46 | _ = h.set_item(py, PyString::new(py, "os").into_object(), PyString::new(py, r.os).into_object()); 47 | _ = h.set_item(py, PyString::new(py, "os_version").into_object(), PyString::new(py, &r.os_version).into_object()); 48 | _ = h.set_item(py, PyString::new(py, "browser_type").into_object(), PyString::new(py, r.browser_type).into_object()); 49 | _ = h.set_item(py, PyString::new(py, "version").into_object(), PyString::new(py, r.version).into_object()); 50 | _ = h.set_item(py, PyString::new(py, "vendor").into_object(), PyString::new(py, r.vendor).into_object()); 51 | Ok(h.into_object()) 52 | } 53 | 54 | pub fn is_crawler(_: Python, agent: &str) -> PyResult { 55 | if agent.is_empty() || agent == "-" { 56 | return Ok(false); 57 | } 58 | 59 | let parser = Parser::new(); 60 | let mut result = WootheeResult::new(); 61 | Ok(parser.try_crawler(agent, &mut result)) 62 | } 63 | -------------------------------------------------------------------------------- /extension/pyo3/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate pyo3; 2 | extern crate woothee; 3 | 4 | use std::collections::HashMap; 5 | use woothee::parser::{Parser, WootheeResult}; 6 | use pyo3::prelude::*; 7 | use pyo3::types::*; 8 | 9 | #[pymodule] 10 | #[pyo3(name = "fast_woothee_pyo3")] 11 | fn init_mod(_py: Python, m: &PyModule) -> PyResult<()> { 12 | 13 | #[pyfunction] 14 | #[pyo3(name = "parse")] 15 | pub fn parse(agent: &str) -> PyResult> { 16 | let parser = Parser::new(); 17 | let result = parser.parse(agent); 18 | let r = match result { 19 | Some(r) => r, 20 | None => WootheeResult::new(), 21 | }; 22 | let mut h = HashMap::new(); 23 | h.insert("name".to_string(), r.name.to_owned()); 24 | h.insert("category".to_string(), r.category.to_string()); 25 | h.insert("os".to_string(), r.os.to_string()); 26 | h.insert("os_version".to_string(), r.os_version.to_string()); 27 | h.insert("browser_type".to_string(), r.browser_type.to_string()); 28 | h.insert("version".to_string(), r.version.to_string()); 29 | h.insert("vendor".to_string(), r.vendor.to_string()); 30 | Ok(h) 31 | } 32 | 33 | #[pyfunction] 34 | #[pyo3(name = "parse2")] 35 | pub fn parse2(agent: &str) -> PyResult { 36 | let parser = Parser::new(); 37 | let result = parser.parse(agent); 38 | let r = match result { 39 | Some(r) => r, 40 | None => WootheeResult::new(), 41 | }; 42 | let gil = Python::acquire_gil(); 43 | let py = gil.python(); 44 | let h = PyDict::new(py); 45 | let _ = h.set_item(PyString::new(py, "name"), PyString::new(py, r.name.as_str())); 46 | let _ = h.set_item(PyString::new(py, "category"), PyString::new(py, r.category.as_str())); 47 | let _ = h.set_item(PyString::new(py, "os"), PyString::new(py, r.os.as_str())); 48 | let _ = h.set_item(PyString::new(py, "os_version"), PyString::new(py, r.os_version.as_str())); 49 | let _ = h.set_item(PyString::new(py, "browser_type"), PyString::new(py, r.browser_type.as_str())); 50 | let _ = h.set_item(PyString::new(py, "version"), PyString::new(py, r.version.as_str())); 51 | let _ = h.set_item(PyString::new(py, "vendor"), PyString::new(py, r.vendor.as_str())); 52 | Ok(h.to_object(py)) 53 | } 54 | 55 | #[pyfunction] 56 | #[pyo3(name = "is_crawler")] 57 | pub fn is_crawler(agent: &str) -> PyResult { 58 | if agent.is_empty() || agent == "-" { 59 | return Ok(false); 60 | } 61 | 62 | let parser = Parser::new(); 63 | let mut result = WootheeResult::new(); 64 | Ok(parser.try_crawler(agent, &mut result)) 65 | } 66 | 67 | m.add_function(wrap_pyfunction!(parse, m)?)?; 68 | m.add_function(wrap_pyfunction!(parse2, m)?)?; 69 | m.add_function(wrap_pyfunction!(is_crawler, m)?)?; 70 | 71 | Ok(()) 72 | } 73 | 74 | -------------------------------------------------------------------------------- /http-client/src/http2-hyper.rs: -------------------------------------------------------------------------------- 1 | use std::error::Error; 2 | use std::net::ToSocketAddrs; 3 | use h2::client; 4 | use http::{HeaderMap, Request}; 5 | use tokio::net::TcpStream; 6 | use tokio_rustls::TlsConnector; 7 | use tokio_rustls::rustls::{OwnedTrustAnchor, RootCertStore, ServerName}; 8 | 9 | const ALPN_H2: &str = "h2"; 10 | static URL: &'static str = "https://http2.github.io"; 11 | 12 | #[tokio::main] 13 | async fn main() -> Result<(), Box> { 14 | let tls_client_config = std::sync::Arc::new({ 15 | let mut root_store = RootCertStore::empty(); 16 | root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| { 17 | OwnedTrustAnchor::from_subject_spki_name_constraints( 18 | ta.subject, 19 | ta.spki, 20 | ta.name_constraints, 21 | ) 22 | })); 23 | 24 | let mut c = tokio_rustls::rustls::ClientConfig::builder() 25 | .with_safe_defaults() 26 | .with_root_certificates(root_store) 27 | .with_no_client_auth(); 28 | c.alpn_protocols.push(ALPN_H2.as_bytes().to_owned()); 29 | c 30 | }); 31 | 32 | let addr = "http2.github.io:443" 33 | .to_socket_addrs() 34 | .unwrap() 35 | .next() 36 | .unwrap(); 37 | 38 | println!("address: {:?}", addr); 39 | 40 | let tcp = TcpStream::connect(&addr).await?; 41 | let dns_name = ServerName::try_from("http2.github.io").unwrap(); 42 | let connector = TlsConnector::from(tls_client_config); 43 | let res = connector.connect(dns_name, tcp).await; 44 | let tls = res.unwrap(); 45 | { 46 | let (_, session) = tls.get_ref(); 47 | let negotiated_protocol = session.alpn_protocol(); 48 | assert_eq!( 49 | Some(ALPN_H2.as_bytes()), 50 | negotiated_protocol.as_ref().map(|x| &**x) 51 | ); 52 | } 53 | 54 | let (mut client, h2) = client::handshake(tls).await?; 55 | 56 | let request = Request::builder() 57 | .uri(URL) 58 | .body(()) 59 | .unwrap(); 60 | 61 | println!("request: {:?}", request); 62 | 63 | let mut trailers = HeaderMap::new(); 64 | trailers.insert("zomg", "hello".parse().unwrap()); 65 | 66 | let (response, mut stream) = client.send_request(request, false).unwrap(); 67 | 68 | stream.send_trailers(trailers).unwrap(); 69 | 70 | tokio::spawn(async move { 71 | if let Err(e) = h2.await { 72 | println!("err={:?}", e); 73 | } 74 | }); 75 | 76 | let response = response.await?; 77 | println!("response: {:?}", response); 78 | 79 | { 80 | let headers = response.headers(); 81 | for header in headers.iter() { 82 | println!("headers: {:?}", header); 83 | } 84 | } 85 | let mut body = response.into_body(); 86 | 87 | while let Some(chunk) = body.data().await { 88 | println!("body: {:?}", chunk?); 89 | } 90 | 91 | Ok(()) 92 | } 93 | -------------------------------------------------------------------------------- /serialize/xml/benches/xmllib.rs: -------------------------------------------------------------------------------- 1 | #![feature(test)] 2 | extern crate test; 3 | extern crate quick_xml; 4 | extern crate xml; 5 | 6 | use xml::reader::{EventReader, XmlEvent}; 7 | use quick_xml::reader::Reader; 8 | use quick_xml::events::Event; 9 | 10 | const XML_STRING: &'static str = r#" 11 | 12 | 13 | 14 | 9 15 | 16 | 10 17 | description 18 | 19 | 20 | 21 | 22 | 1502953063279 23 | 24 | 25 | "#; 26 | 27 | fn _bench_xmlrs() { 28 | let reader = EventReader::from_str(XML_STRING); 29 | 30 | for e in reader { 31 | match e { 32 | Ok(XmlEvent::StartElement { name, attributes, .. }) => { 33 | format!("tag-name: {:?} attr: {:?}", 34 | name.local_name, 35 | attributes.into_iter().map(|a| { 36 | format!("{}={}", a.name.local_name, a.value) 37 | }).collect::>()); 38 | }, 39 | Ok(XmlEvent::EndElement { .. }) => { 40 | //println!("tag-name(e): {:?}", name); 41 | } 42 | Ok(XmlEvent::Characters(s)) => { 43 | let _ = format!(" text: {}", s); 44 | }, 45 | Err(e) => panic!("error: {:?}", e), 46 | _ => (), 47 | } 48 | } 49 | } 50 | 51 | fn _bench_quickxml() { 52 | let mut buf = Vec::new(); 53 | let mut reader = Reader::from_str(XML_STRING); 54 | reader.trim_text(true); 55 | 56 | loop { 57 | match reader.read_event(&mut buf) { 58 | Ok(Event::Start(ref e)) | Ok(Event::Empty(ref e)) => { 59 | let _ = format!("tag-name: {:?} attr: {:?}", std::str::from_utf8(e.name()).expect("convert error"), 60 | e.attributes().map(|a| { 61 | let v = a.unwrap(); 62 | format!("{}={}", 63 | std::str::from_utf8(v.key).expect("convert error"), 64 | std::str::from_utf8(v.value).expect("convert error")) 65 | }).collect::>()); 66 | }, 67 | Ok(Event::Text(e)) => { 68 | let _ = format!(" text: {}", e.unescape_and_decode(&reader).unwrap()); 69 | }, 70 | Ok(Event::Eof) => break, 71 | Err(e) => panic!("error: {}: {:?}", reader.buffer_position(), e), 72 | _ => (), 73 | } 74 | } 75 | } 76 | 77 | #[cfg(test)] 78 | mod tests { 79 | use super::*; 80 | use test::Bencher; 81 | 82 | #[bench] 83 | fn bench_xmlrs(b: &mut Bencher) { 84 | b.iter(|| _bench_xmlrs()); 85 | } 86 | 87 | #[bench] 88 | fn bench_quickxml(b: &mut Bencher) { 89 | b.iter(|| _bench_quickxml()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /extension/cpython/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "aho-corasick" 7 | version = "0.7.19" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" 10 | dependencies = [ 11 | "memchr", 12 | ] 13 | 14 | [[package]] 15 | name = "autocfg" 16 | version = "1.1.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 19 | 20 | [[package]] 21 | name = "cpython" 22 | version = "0.7.1" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "3052106c29da7390237bc2310c1928335733b286287754ea85e6093d2495280e" 25 | dependencies = [ 26 | "libc", 27 | "num-traits", 28 | "paste", 29 | "python3-sys", 30 | ] 31 | 32 | [[package]] 33 | name = "fast-woothee" 34 | version = "0.1.0" 35 | dependencies = [ 36 | "cpython", 37 | "woothee", 38 | ] 39 | 40 | [[package]] 41 | name = "lazy_static" 42 | version = "1.4.0" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 45 | 46 | [[package]] 47 | name = "libc" 48 | version = "0.2.29" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "8a014d9226c2cc402676fbe9ea2e15dd5222cd1dd57f576b5b283178c944a264" 51 | 52 | [[package]] 53 | name = "memchr" 54 | version = "2.5.0" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 57 | 58 | [[package]] 59 | name = "num-traits" 60 | version = "0.2.15" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 63 | dependencies = [ 64 | "autocfg", 65 | ] 66 | 67 | [[package]] 68 | name = "paste" 69 | version = "1.0.9" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" 72 | 73 | [[package]] 74 | name = "python3-sys" 75 | version = "0.7.1" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "49f8b50d72fb3015735aa403eebf19bbd72c093bfeeae24ee798be5f2f1aab52" 78 | dependencies = [ 79 | "libc", 80 | "regex", 81 | ] 82 | 83 | [[package]] 84 | name = "regex" 85 | version = "1.7.0" 86 | source = "registry+https://github.com/rust-lang/crates.io-index" 87 | checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" 88 | dependencies = [ 89 | "aho-corasick", 90 | "memchr", 91 | "regex-syntax", 92 | ] 93 | 94 | [[package]] 95 | name = "regex-syntax" 96 | version = "0.6.28" 97 | source = "registry+https://github.com/rust-lang/crates.io-index" 98 | checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" 99 | 100 | [[package]] 101 | name = "woothee" 102 | version = "0.13.0" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "896174c6a4779d4d7d4523dd27aef7d46609eda2497e370f6c998325c6bf6971" 105 | dependencies = [ 106 | "lazy_static", 107 | "regex", 108 | ] 109 | -------------------------------------------------------------------------------- /http-client/src/rust-websocket.rs: -------------------------------------------------------------------------------- 1 | extern crate websocket; 2 | use std::thread; 3 | use std::time::Duration; 4 | use std::sync::mpsc; 5 | use std::net::TcpStream; 6 | use websocket::{Message, OwnedMessage}; 7 | use websocket::client::ClientBuilder; 8 | use websocket::result::WebSocketError; 9 | use websocket::sync::sender as wsender; 10 | use websocket::sync::receiver as wreceiver; 11 | 12 | fn sendloop(mut sender: wsender::Writer, rx: mpsc::Receiver) { 13 | let mut cnt = 0; 14 | loop { 15 | cnt += 1; 16 | let text = format!("Hello {:?}", cnt).to_string(); 17 | let msg = Message::text(text); 18 | let _ = match sender.send_message(&msg) { 19 | Ok(r) => r, 20 | Err(e) => { 21 | println!("Send error: {:?}", e); 22 | return; 23 | } 24 | }; 25 | println!("send msg: {:?}", msg); 26 | 27 | let message = match rx.try_recv() { 28 | Ok(m) => m, 29 | Err(_) => { 30 | return; 31 | } 32 | }; 33 | match message { 34 | OwnedMessage::Close(_) => { 35 | return; 36 | } 37 | _ => (), 38 | } 39 | 40 | match sender.send_message(&message) { 41 | Ok(()) => (), 42 | Err(e) => { 43 | println!("Send Loop: {:?}", e); 44 | let _ = sender.send_message(&Message::close()); 45 | return; 46 | } 47 | } 48 | std::thread::sleep(Duration::from_millis(1500)); 49 | } 50 | } 51 | 52 | fn recvloop(mut receiver: wreceiver::Reader, tx: mpsc::Sender) { 53 | for msg in receiver.incoming_messages() { 54 | let msg: OwnedMessage = match msg { 55 | Ok(m) => m, 56 | Err(WebSocketError::NoDataAvailable) => return, // connection close by server 57 | Err(e) => { 58 | println!("Receive Loop First: {}", e); 59 | break; 60 | } 61 | }; 62 | 63 | match msg { 64 | OwnedMessage::Close(_) => { 65 | println!("recv Close"); 66 | let _ = tx.send(OwnedMessage::Close(None)); 67 | return; 68 | } 69 | OwnedMessage::Ping(ping) => { 70 | println!("recv Ping"); 71 | match tx.send(OwnedMessage::Pong(ping)) { 72 | Ok(()) => println!("send Pong"), 73 | Err(e) => { 74 | println!("Receive Loop: {:?}", e); 75 | return; 76 | } 77 | } 78 | } 79 | _ => println!("recv msg: {:?}", msg), 80 | } 81 | } 82 | } 83 | 84 | fn main() { 85 | let client = ClientBuilder::new("ws://127.0.0.1:9999") 86 | .expect("fail new ws client") 87 | .add_protocol("rust-websocket") 88 | .connect_insecure().unwrap(); 89 | println!("connected"); 90 | 91 | let (receiver, sender) = client.split().expect("fail client split()"); 92 | let (tx, rx) = mpsc::channel(); 93 | let send_loop = thread::spawn(move || sendloop(sender, rx)); 94 | let receive_loop = thread::spawn(move || recvloop(receiver, tx)); 95 | 96 | let _ = send_loop.join(); 97 | let _ = receive_loop.join(); 98 | println!("end"); 99 | } 100 | -------------------------------------------------------------------------------- /graphics/metalexample/src/main.rs: -------------------------------------------------------------------------------- 1 | use metal::*; 2 | use std::mem; 3 | use image::{DynamicImage, save_buffer, ColorType}; 4 | 5 | const PROGRAM: &str = "#include 6 | 7 | using namespace metal; 8 | 9 | struct Vertex { 10 | float4 position [[position]]; 11 | float4 color; 12 | }; 13 | 14 | vertex Vertex VertexShader( 15 | uint vertexID [[vertex_id]], 16 | device Vertex * vertices [[buffer(0)]] 17 | ) { 18 | return vertices[vertexID]; 19 | } 20 | 21 | fragment float4 FragmentShader(Vertex in [[stage_in]]) { 22 | return in.color; 23 | }"; 24 | 25 | fn main() { 26 | let device = Device::system_default().unwrap(); 27 | 28 | let options = CompileOptions::new(); 29 | let library = device.new_library_with_source(PROGRAM, &options).expect("new library"); 30 | 31 | let vs = library.get_function("VertexShader", None).expect("get_function(vertex)"); 32 | let fs = library.get_function("FragmentShader", None).expect("get_function(fragment)"); 33 | 34 | let rpld = RenderPipelineDescriptor::new(); 35 | rpld.set_vertex_function(Some(&vs)); 36 | rpld.set_fragment_function(Some(&fs)); 37 | rpld.color_attachments().object_at(0).unwrap().set_pixel_format(MTLPixelFormat::RGBA8Unorm); 38 | let rps = device.new_render_pipeline_state(&rpld).unwrap(); 39 | 40 | let vbuf = { 41 | let vertex_data = [ 42 | 0.0f32, 0.75, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 43 | -0.75, -0.75, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 44 | 0.75, -0.75, 0.0, 1.0, 0.0, 0.5, 1.0, 1.0, 45 | ]; 46 | 47 | device.new_buffer_with_data( 48 | unsafe { mem::transmute(vertex_data.as_ptr()) }, 49 | (vertex_data.len() * mem::size_of::()) as u64, 50 | MTLResourceOptions::StorageModeManaged) 51 | }; 52 | 53 | let td = TextureDescriptor::new(); 54 | td.set_pixel_format(MTLPixelFormat::RGBA8Unorm); 55 | td.set_width(512); 56 | td.set_height(512); 57 | td.set_storage_mode(MTLStorageMode::Managed); 58 | 59 | let texture = device.new_texture(&td); 60 | 61 | let cq = device.new_command_queue(); 62 | let cb = cq.new_command_buffer(); 63 | 64 | let rpd = RenderPassDescriptor::new(); 65 | rpd.color_attachments().object_at(0).unwrap().set_load_action(MTLLoadAction::Clear); 66 | rpd.color_attachments().object_at(0).unwrap().set_store_action(MTLStoreAction::Store); 67 | rpd.color_attachments().object_at(0).unwrap().set_clear_color(MTLClearColor::new(0.35, 0.65, 0.85, 0.5)); 68 | rpd.color_attachments().object_at(0).unwrap().set_texture(Some(&texture)); 69 | 70 | let rce = cb.new_render_command_encoder(&rpd); 71 | rce.set_render_pipeline_state(&rps); 72 | rce.set_vertex_buffer(0, Some(&vbuf), 0); 73 | rce.draw_primitives(MTLPrimitiveType::Triangle, 0, 3); 74 | rce.end_encoding(); 75 | 76 | let bce = cb.new_blit_command_encoder(); 77 | bce.synchronize_resource(&texture); 78 | bce.end_encoding(); 79 | 80 | cb.commit(); 81 | cb.wait_until_completed(); 82 | 83 | let ref mut img = DynamicImage::new_rgba8(texture.width() as u32, texture.height() as u32); 84 | let bytes_per_row = 4 * texture.width(); 85 | let region = MTLRegion{ 86 | origin: MTLOrigin { x: 0, y: 0, z: 0 }, 87 | size: MTLSize { 88 | width: texture.width(), 89 | height: texture.height(), 90 | depth: 1, 91 | } 92 | }; 93 | let buf = img.clone().into_rgba8(); 94 | texture.get_bytes( 95 | unsafe { mem::transmute(buf.as_ptr()) }, 96 | bytes_per_row, region, 0); 97 | let _ = save_buffer("triangle.png", &buf, texture.width() as u32, texture.height() as u32, ColorType::Rgba8); 98 | } 99 | -------------------------------------------------------------------------------- /databases/rusqlite_sqlite/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.7.6" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" 10 | dependencies = [ 11 | "getrandom", 12 | "once_cell", 13 | "version_check", 14 | ] 15 | 16 | [[package]] 17 | name = "bitflags" 18 | version = "1.3.2" 19 | source = "registry+https://github.com/rust-lang/crates.io-index" 20 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 21 | 22 | [[package]] 23 | name = "cfg-if" 24 | version = "1.0.0" 25 | source = "registry+https://github.com/rust-lang/crates.io-index" 26 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 27 | 28 | [[package]] 29 | name = "fallible-iterator" 30 | version = "0.2.0" 31 | source = "registry+https://github.com/rust-lang/crates.io-index" 32 | checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" 33 | 34 | [[package]] 35 | name = "fallible-streaming-iterator" 36 | version = "0.1.9" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" 39 | 40 | [[package]] 41 | name = "getrandom" 42 | version = "0.2.8" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" 45 | dependencies = [ 46 | "cfg-if", 47 | "libc", 48 | "wasi", 49 | ] 50 | 51 | [[package]] 52 | name = "hashbrown" 53 | version = "0.12.3" 54 | source = "registry+https://github.com/rust-lang/crates.io-index" 55 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 56 | dependencies = [ 57 | "ahash", 58 | ] 59 | 60 | [[package]] 61 | name = "hashlink" 62 | version = "0.8.1" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" 65 | dependencies = [ 66 | "hashbrown", 67 | ] 68 | 69 | [[package]] 70 | name = "libc" 71 | version = "0.2.139" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" 74 | 75 | [[package]] 76 | name = "libsqlite3-sys" 77 | version = "0.25.2" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" 80 | dependencies = [ 81 | "pkg-config", 82 | "vcpkg", 83 | ] 84 | 85 | [[package]] 86 | name = "once_cell" 87 | version = "1.17.1" 88 | source = "registry+https://github.com/rust-lang/crates.io-index" 89 | checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" 90 | 91 | [[package]] 92 | name = "pkg-config" 93 | version = "0.3.26" 94 | source = "registry+https://github.com/rust-lang/crates.io-index" 95 | checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" 96 | 97 | [[package]] 98 | name = "rusqlite" 99 | version = "0.28.0" 100 | source = "registry+https://github.com/rust-lang/crates.io-index" 101 | checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" 102 | dependencies = [ 103 | "bitflags", 104 | "fallible-iterator", 105 | "fallible-streaming-iterator", 106 | "hashlink", 107 | "libsqlite3-sys", 108 | "smallvec", 109 | ] 110 | 111 | [[package]] 112 | name = "rusqlite_sqlite" 113 | version = "0.1.0" 114 | dependencies = [ 115 | "rusqlite", 116 | ] 117 | 118 | [[package]] 119 | name = "smallvec" 120 | version = "1.10.0" 121 | source = "registry+https://github.com/rust-lang/crates.io-index" 122 | checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" 123 | 124 | [[package]] 125 | name = "vcpkg" 126 | version = "0.2.15" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 129 | 130 | [[package]] 131 | name = "version_check" 132 | version = "0.9.4" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 135 | 136 | [[package]] 137 | name = "wasi" 138 | version = "0.11.0+wasi-snapshot-preview1" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 141 | -------------------------------------------------------------------------------- /fuse/src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate env_logger; 2 | extern crate fuse; 3 | extern crate time; 4 | extern crate libc; 5 | 6 | use std::env; 7 | use std::collections::HashMap; 8 | use std::ffi::OsStr; 9 | use fuse::{FileAttr, FileType, Filesystem, Request, ReplyEntry, ReplyDirectory, ReplyAttr, ReplyCreate, ReplyWrite, ReplyData}; 10 | use time::Timespec; 11 | use libc::{ENOENT, EACCES}; 12 | 13 | const TTL: Timespec = Timespec { sec: 1, nsec: 0 }; 14 | 15 | struct MemFS { 16 | inodes: HashMap, // 17 | datas: HashMap // 18 | } 19 | 20 | fn file_create(ino: u64, size: u64, ftype: FileType) -> FileAttr { 21 | let t = time::now().to_timespec(); 22 | FileAttr { 23 | ino: ino, 24 | size: size, 25 | blocks: 0, 26 | atime: t, 27 | mtime: t, 28 | ctime: t, 29 | crtime: t, 30 | kind: ftype, 31 | perm: match ftype { 32 | FileType::Directory => 0o755, 33 | _ => 0o644, 34 | }, 35 | nlink: match ftype { 36 | FileType::Directory => 2, 37 | _ => 1, 38 | }, 39 | uid: 501, 40 | gid: 20, 41 | rdev: 0, 42 | flags: 0 43 | } 44 | } 45 | 46 | impl Filesystem for MemFS { 47 | fn getattr(&mut self, _req: &Request, ino: u64, reply: ReplyAttr) { 48 | for (&inode, f) in self.inodes.iter() { 49 | if ino == inode { 50 | reply.attr(&TTL, &f.2); 51 | return; 52 | } 53 | } 54 | reply.error(ENOENT); 55 | } 56 | 57 | fn readdir(&mut self, _req: &Request, ino: u64, _fh: u64, offset: i64, mut reply: ReplyDirectory) { 58 | if offset > 0 { 59 | reply.ok(); 60 | return; 61 | } 62 | 63 | reply.add(1, 0, FileType::Directory, "."); 64 | reply.add(2, 1, FileType::Directory, ".."); 65 | let mut reply_add_offset = 2; 66 | for (_, f) in self.inodes.iter() { 67 | if ino == f.0 { 68 | let attr = f.2; 69 | let name = &f.1; 70 | reply.add(attr.ino, reply_add_offset, attr.kind, name); 71 | reply_add_offset += 1; 72 | } 73 | } 74 | reply.ok(); 75 | } 76 | 77 | fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) { 78 | for (_, f) in self.inodes.iter() { 79 | if f.0 == parent && name.to_str().unwrap() == f.1.as_str() { 80 | reply.entry(&TTL, &f.2, 0); 81 | return; 82 | } 83 | } 84 | reply.error(ENOENT); 85 | } 86 | 87 | fn create(&mut self, _req: &Request, parent: u64, name: &OsStr, _mode: u32, _flag: u32, reply: ReplyCreate) { 88 | let inode = time::now().to_timespec().sec as u64; 89 | let f = file_create(inode, 0, FileType::RegularFile); 90 | self.inodes.insert(inode, (parent, name.to_str().unwrap().to_string(), f)); 91 | reply.created(&TTL, &f, 0, 0, 0); 92 | } 93 | 94 | fn setattr(&mut self, _req: &Request, ino: u64, _mode: Option, _uid: Option, 95 | _gid: Option, _size: Option, _atime: Option, 96 | _mtime: Option, _fh: Option, _crtime: Option, 97 | _chgtime: Option, _bkuptime: Option, _flags: Option, 98 | reply: ReplyAttr) { 99 | match self.inodes.get(&ino) { 100 | Some(f) => reply.attr(&TTL, &f.2), 101 | None => reply.error(EACCES), 102 | } 103 | } 104 | 105 | fn write(&mut self, _req: &Request, ino: u64, _fh: u64, _offset: i64, data: &[u8], _flags: u32, reply: ReplyWrite) { 106 | let length: usize = data.len(); 107 | let x = String::from_utf8(data.to_vec()).expect("fail to-string"); 108 | self.datas.insert(ino, x); 109 | if let Some(f) = self.inodes.get_mut(&ino) { 110 | let parent_ino = f.0; 111 | let name = f.1.clone(); 112 | *f = (parent_ino, name, file_create(ino, length as u64, FileType::RegularFile)); 113 | } 114 | reply.written(length as u32); 115 | } 116 | 117 | fn read(&mut self, _req: &Request, ino: u64, _fh: u64, _offset: i64, _size: u32, reply: ReplyData) { 118 | match self.datas.get(&ino) { 119 | Some(x) => reply.data(x.as_bytes()), 120 | None => reply.error(EACCES), 121 | } 122 | } 123 | } 124 | 125 | fn main() { 126 | env_logger::init(); 127 | let mountpoint = env::args_os().nth(1).expect("usage: backlogfs MOUNTPOINT"); 128 | let mut inodes = HashMap::new(); 129 | let datas = HashMap::new(); 130 | inodes.insert(1, (0, "/".to_string(), file_create(1, 0, FileType::Directory))); 131 | fuse::mount(MemFS{inodes: inodes, datas: datas}, &mountpoint, &[]).expect("fail mount()"); 132 | } 133 | -------------------------------------------------------------------------------- /serialize/protobuf/src/person.rs: -------------------------------------------------------------------------------- 1 | // This file is generated by rust-protobuf 3.2.0. Do not edit 2 | // .proto file is parsed by protoc --rust-out=... 3 | // @generated 4 | 5 | // https://github.com/rust-lang/rust-clippy/issues/702 6 | #![allow(unknown_lints)] 7 | #![allow(clippy::all)] 8 | 9 | #![allow(unused_attributes)] 10 | #![cfg_attr(rustfmt, rustfmt::skip)] 11 | 12 | #![allow(box_pointers)] 13 | #![allow(dead_code)] 14 | #![allow(missing_docs)] 15 | #![allow(non_camel_case_types)] 16 | #![allow(non_snake_case)] 17 | #![allow(non_upper_case_globals)] 18 | #![allow(trivial_casts)] 19 | #![allow(unused_results)] 20 | #![allow(unused_mut)] 21 | 22 | //! Generated file from `proto/person.proto` 23 | 24 | /// Generated files are compatible only with the same version 25 | /// of protobuf runtime. 26 | const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_3_2_0; 27 | 28 | #[derive(PartialEq,Clone,Default,Debug)] 29 | // @@protoc_insertion_point(message:Person) 30 | pub struct Person { 31 | // message fields 32 | // @@protoc_insertion_point(field:Person.name) 33 | pub name: ::std::string::String, 34 | // @@protoc_insertion_point(field:Person.id) 35 | pub id: i32, 36 | // @@protoc_insertion_point(field:Person.email) 37 | pub email: ::std::option::Option<::std::string::String>, 38 | // special fields 39 | // @@protoc_insertion_point(special_field:Person.special_fields) 40 | pub special_fields: ::protobuf::SpecialFields, 41 | } 42 | 43 | impl<'a> ::std::default::Default for &'a Person { 44 | fn default() -> &'a Person { 45 | ::default_instance() 46 | } 47 | } 48 | 49 | impl Person { 50 | pub fn new() -> Person { 51 | ::std::default::Default::default() 52 | } 53 | 54 | fn generated_message_descriptor_data() -> ::protobuf::reflect::GeneratedMessageDescriptorData { 55 | let mut fields = ::std::vec::Vec::with_capacity(3); 56 | let mut oneofs = ::std::vec::Vec::with_capacity(0); 57 | fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( 58 | "name", 59 | |m: &Person| { &m.name }, 60 | |m: &mut Person| { &mut m.name }, 61 | )); 62 | fields.push(::protobuf::reflect::rt::v2::make_simpler_field_accessor::<_, _>( 63 | "id", 64 | |m: &Person| { &m.id }, 65 | |m: &mut Person| { &mut m.id }, 66 | )); 67 | fields.push(::protobuf::reflect::rt::v2::make_option_accessor::<_, _>( 68 | "email", 69 | |m: &Person| { &m.email }, 70 | |m: &mut Person| { &mut m.email }, 71 | )); 72 | ::protobuf::reflect::GeneratedMessageDescriptorData::new_2::( 73 | "Person", 74 | fields, 75 | oneofs, 76 | ) 77 | } 78 | } 79 | 80 | impl ::protobuf::Message for Person { 81 | const NAME: &'static str = "Person"; 82 | 83 | fn is_initialized(&self) -> bool { 84 | true 85 | } 86 | 87 | fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::Result<()> { 88 | while let Some(tag) = is.read_raw_tag_or_eof()? { 89 | match tag { 90 | 10 => { 91 | self.name = is.read_string()?; 92 | }, 93 | 16 => { 94 | self.id = is.read_int32()?; 95 | }, 96 | 26 => { 97 | self.email = ::std::option::Option::Some(is.read_string()?); 98 | }, 99 | tag => { 100 | ::protobuf::rt::read_unknown_or_skip_group(tag, is, self.special_fields.mut_unknown_fields())?; 101 | }, 102 | }; 103 | } 104 | ::std::result::Result::Ok(()) 105 | } 106 | 107 | // Compute sizes of nested messages 108 | #[allow(unused_variables)] 109 | fn compute_size(&self) -> u64 { 110 | let mut my_size = 0; 111 | if !self.name.is_empty() { 112 | my_size += ::protobuf::rt::string_size(1, &self.name); 113 | } 114 | if self.id != 0 { 115 | my_size += ::protobuf::rt::int32_size(2, self.id); 116 | } 117 | if let Some(v) = self.email.as_ref() { 118 | my_size += ::protobuf::rt::string_size(3, &v); 119 | } 120 | my_size += ::protobuf::rt::unknown_fields_size(self.special_fields.unknown_fields()); 121 | self.special_fields.cached_size().set(my_size as u32); 122 | my_size 123 | } 124 | 125 | fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::Result<()> { 126 | if !self.name.is_empty() { 127 | os.write_string(1, &self.name)?; 128 | } 129 | if self.id != 0 { 130 | os.write_int32(2, self.id)?; 131 | } 132 | if let Some(v) = self.email.as_ref() { 133 | os.write_string(3, v)?; 134 | } 135 | os.write_unknown_fields(self.special_fields.unknown_fields())?; 136 | ::std::result::Result::Ok(()) 137 | } 138 | 139 | fn special_fields(&self) -> &::protobuf::SpecialFields { 140 | &self.special_fields 141 | } 142 | 143 | fn mut_special_fields(&mut self) -> &mut ::protobuf::SpecialFields { 144 | &mut self.special_fields 145 | } 146 | 147 | fn new() -> Person { 148 | Person::new() 149 | } 150 | 151 | fn clear(&mut self) { 152 | self.name.clear(); 153 | self.id = 0; 154 | self.email = ::std::option::Option::None; 155 | self.special_fields.clear(); 156 | } 157 | 158 | fn default_instance() -> &'static Person { 159 | static instance: Person = Person { 160 | name: ::std::string::String::new(), 161 | id: 0, 162 | email: ::std::option::Option::None, 163 | special_fields: ::protobuf::SpecialFields::new(), 164 | }; 165 | &instance 166 | } 167 | } 168 | 169 | impl ::protobuf::MessageFull for Person { 170 | fn descriptor() -> ::protobuf::reflect::MessageDescriptor { 171 | static descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::Lazy::new(); 172 | descriptor.get(|| file_descriptor().message_by_package_relative_name("Person").unwrap()).clone() 173 | } 174 | } 175 | 176 | impl ::std::fmt::Display for Person { 177 | fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { 178 | ::protobuf::text_format::fmt(self, f) 179 | } 180 | } 181 | 182 | impl ::protobuf::reflect::ProtobufValue for Person { 183 | type RuntimeType = ::protobuf::reflect::rt::RuntimeTypeMessage; 184 | } 185 | 186 | static file_descriptor_proto_data: &'static [u8] = b"\ 187 | \n\x12proto/person.proto\"Q\n\x06Person\x12\x12\n\x04name\x18\x01\x20\ 188 | \x01(\tR\x04name\x12\x0e\n\x02id\x18\x02\x20\x01(\x05R\x02id\x12\x19\n\ 189 | \x05email\x18\x03\x20\x01(\tH\0R\x05email\x88\x01\x01B\x08\n\x06_emailJ\ 190 | \xdd\x01\n\x06\x12\x04\0\0\x06\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\ 191 | \x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x0e\ 192 | \n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x14\n\x0c\n\x05\x04\0\x02\0\x05\ 193 | \x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x0f\n\x0c\ 194 | \n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\x13\n\x0b\n\x04\x04\0\x02\x01\x12\ 195 | \x03\x04\x04\x11\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\t\n\x0c\n\ 196 | \x05\x04\0\x02\x01\x01\x12\x03\x04\n\x0c\n\x0c\n\x05\x04\0\x02\x01\x03\ 197 | \x12\x03\x04\x0f\x10\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x1e\n\x0c\ 198 | \n\x05\x04\0\x02\x02\x04\x12\x03\x05\x04\x0c\n\x0c\n\x05\x04\0\x02\x02\ 199 | \x05\x12\x03\x05\r\x13\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\x14\x19\ 200 | \n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x1c\x1db\x06proto3\ 201 | "; 202 | 203 | /// `FileDescriptorProto` object which was a source for this generated file 204 | fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { 205 | static file_descriptor_proto_lazy: ::protobuf::rt::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::Lazy::new(); 206 | file_descriptor_proto_lazy.get(|| { 207 | ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() 208 | }) 209 | } 210 | 211 | /// `FileDescriptor` object which allows dynamic access to files 212 | pub fn file_descriptor() -> &'static ::protobuf::reflect::FileDescriptor { 213 | static generated_file_descriptor_lazy: ::protobuf::rt::Lazy<::protobuf::reflect::GeneratedFileDescriptor> = ::protobuf::rt::Lazy::new(); 214 | static file_descriptor: ::protobuf::rt::Lazy<::protobuf::reflect::FileDescriptor> = ::protobuf::rt::Lazy::new(); 215 | file_descriptor.get(|| { 216 | let generated_file_descriptor = generated_file_descriptor_lazy.get(|| { 217 | let mut deps = ::std::vec::Vec::with_capacity(0); 218 | let mut messages = ::std::vec::Vec::with_capacity(1); 219 | messages.push(Person::generated_message_descriptor_data()); 220 | let mut enums = ::std::vec::Vec::with_capacity(0); 221 | ::protobuf::reflect::GeneratedFileDescriptor::new_generated( 222 | file_descriptor_proto(), 223 | deps, 224 | messages, 225 | enums, 226 | ) 227 | }); 228 | ::protobuf::reflect::FileDescriptor::new_generated_2(generated_file_descriptor) 229 | }) 230 | } 231 | -------------------------------------------------------------------------------- /graphics/metalexample/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "adler" 7 | version = "1.0.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 10 | 11 | [[package]] 12 | name = "adler32" 13 | version = "1.2.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" 16 | 17 | [[package]] 18 | name = "autocfg" 19 | version = "1.3.0" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" 22 | 23 | [[package]] 24 | name = "bitflags" 25 | version = "1.3.2" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 28 | 29 | [[package]] 30 | name = "bitflags" 31 | version = "2.6.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 34 | 35 | [[package]] 36 | name = "block" 37 | version = "0.1.6" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" 40 | 41 | [[package]] 42 | name = "bytemuck" 43 | version = "1.17.0" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" 46 | 47 | [[package]] 48 | name = "byteorder" 49 | version = "1.5.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" 52 | 53 | [[package]] 54 | name = "cfg-if" 55 | version = "1.0.0" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 58 | 59 | [[package]] 60 | name = "color_quant" 61 | version = "1.1.0" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" 64 | 65 | [[package]] 66 | name = "core-foundation" 67 | version = "0.9.4" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" 70 | dependencies = [ 71 | "core-foundation-sys", 72 | "libc", 73 | ] 74 | 75 | [[package]] 76 | name = "core-foundation-sys" 77 | version = "0.8.7" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 80 | 81 | [[package]] 82 | name = "core-graphics-types" 83 | version = "0.1.3" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" 86 | dependencies = [ 87 | "bitflags 1.3.2", 88 | "core-foundation", 89 | "libc", 90 | ] 91 | 92 | [[package]] 93 | name = "crc32fast" 94 | version = "1.4.2" 95 | source = "registry+https://github.com/rust-lang/crates.io-index" 96 | checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" 97 | dependencies = [ 98 | "cfg-if", 99 | ] 100 | 101 | [[package]] 102 | name = "crossbeam-deque" 103 | version = "0.8.5" 104 | source = "registry+https://github.com/rust-lang/crates.io-index" 105 | checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" 106 | dependencies = [ 107 | "crossbeam-epoch", 108 | "crossbeam-utils", 109 | ] 110 | 111 | [[package]] 112 | name = "crossbeam-epoch" 113 | version = "0.9.18" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" 116 | dependencies = [ 117 | "crossbeam-utils", 118 | ] 119 | 120 | [[package]] 121 | name = "crossbeam-utils" 122 | version = "0.8.20" 123 | source = "registry+https://github.com/rust-lang/crates.io-index" 124 | checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" 125 | 126 | [[package]] 127 | name = "deflate" 128 | version = "0.8.6" 129 | source = "registry+https://github.com/rust-lang/crates.io-index" 130 | checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" 131 | dependencies = [ 132 | "adler32", 133 | "byteorder", 134 | ] 135 | 136 | [[package]] 137 | name = "either" 138 | version = "1.13.0" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 141 | 142 | [[package]] 143 | name = "foreign-types" 144 | version = "0.5.0" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" 147 | dependencies = [ 148 | "foreign-types-macros", 149 | "foreign-types-shared", 150 | ] 151 | 152 | [[package]] 153 | name = "foreign-types-macros" 154 | version = "0.2.3" 155 | source = "registry+https://github.com/rust-lang/crates.io-index" 156 | checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" 157 | dependencies = [ 158 | "proc-macro2", 159 | "quote", 160 | "syn", 161 | ] 162 | 163 | [[package]] 164 | name = "foreign-types-shared" 165 | version = "0.3.1" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" 168 | 169 | [[package]] 170 | name = "gif" 171 | version = "0.11.4" 172 | source = "registry+https://github.com/rust-lang/crates.io-index" 173 | checksum = "3edd93c6756b4dfaf2709eafcc345ba2636565295c198a9cfbf75fa5e3e00b06" 174 | dependencies = [ 175 | "color_quant", 176 | "weezl", 177 | ] 178 | 179 | [[package]] 180 | name = "image" 181 | version = "0.23.14" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" 184 | dependencies = [ 185 | "bytemuck", 186 | "byteorder", 187 | "color_quant", 188 | "gif", 189 | "jpeg-decoder", 190 | "num-iter", 191 | "num-rational", 192 | "num-traits", 193 | "png", 194 | "scoped_threadpool", 195 | "tiff", 196 | ] 197 | 198 | [[package]] 199 | name = "jpeg-decoder" 200 | version = "0.1.22" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" 203 | dependencies = [ 204 | "rayon", 205 | ] 206 | 207 | [[package]] 208 | name = "libc" 209 | version = "0.2.158" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" 212 | 213 | [[package]] 214 | name = "log" 215 | version = "0.4.22" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" 218 | 219 | [[package]] 220 | name = "malloc_buf" 221 | version = "0.0.6" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" 224 | dependencies = [ 225 | "libc", 226 | ] 227 | 228 | [[package]] 229 | name = "metal" 230 | version = "0.29.0" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "7ecfd3296f8c56b7c1f6fbac3c71cefa9d78ce009850c45000015f206dc7fa21" 233 | dependencies = [ 234 | "bitflags 2.6.0", 235 | "block", 236 | "core-graphics-types", 237 | "foreign-types", 238 | "log", 239 | "objc", 240 | "paste", 241 | ] 242 | 243 | [[package]] 244 | name = "metalexample" 245 | version = "0.1.0" 246 | dependencies = [ 247 | "image", 248 | "metal", 249 | ] 250 | 251 | [[package]] 252 | name = "miniz_oxide" 253 | version = "0.3.7" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" 256 | dependencies = [ 257 | "adler32", 258 | ] 259 | 260 | [[package]] 261 | name = "miniz_oxide" 262 | version = "0.4.4" 263 | source = "registry+https://github.com/rust-lang/crates.io-index" 264 | checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" 265 | dependencies = [ 266 | "adler", 267 | "autocfg", 268 | ] 269 | 270 | [[package]] 271 | name = "num-integer" 272 | version = "0.1.46" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" 275 | dependencies = [ 276 | "num-traits", 277 | ] 278 | 279 | [[package]] 280 | name = "num-iter" 281 | version = "0.1.45" 282 | source = "registry+https://github.com/rust-lang/crates.io-index" 283 | checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" 284 | dependencies = [ 285 | "autocfg", 286 | "num-integer", 287 | "num-traits", 288 | ] 289 | 290 | [[package]] 291 | name = "num-rational" 292 | version = "0.3.2" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" 295 | dependencies = [ 296 | "autocfg", 297 | "num-integer", 298 | "num-traits", 299 | ] 300 | 301 | [[package]] 302 | name = "num-traits" 303 | version = "0.2.19" 304 | source = "registry+https://github.com/rust-lang/crates.io-index" 305 | checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" 306 | dependencies = [ 307 | "autocfg", 308 | ] 309 | 310 | [[package]] 311 | name = "objc" 312 | version = "0.2.7" 313 | source = "registry+https://github.com/rust-lang/crates.io-index" 314 | checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" 315 | dependencies = [ 316 | "malloc_buf", 317 | ] 318 | 319 | [[package]] 320 | name = "paste" 321 | version = "1.0.15" 322 | source = "registry+https://github.com/rust-lang/crates.io-index" 323 | checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" 324 | 325 | [[package]] 326 | name = "png" 327 | version = "0.16.8" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" 330 | dependencies = [ 331 | "bitflags 1.3.2", 332 | "crc32fast", 333 | "deflate", 334 | "miniz_oxide 0.3.7", 335 | ] 336 | 337 | [[package]] 338 | name = "proc-macro2" 339 | version = "1.0.86" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" 342 | dependencies = [ 343 | "unicode-ident", 344 | ] 345 | 346 | [[package]] 347 | name = "quote" 348 | version = "1.0.37" 349 | source = "registry+https://github.com/rust-lang/crates.io-index" 350 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 351 | dependencies = [ 352 | "proc-macro2", 353 | ] 354 | 355 | [[package]] 356 | name = "rayon" 357 | version = "1.10.0" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" 360 | dependencies = [ 361 | "either", 362 | "rayon-core", 363 | ] 364 | 365 | [[package]] 366 | name = "rayon-core" 367 | version = "1.12.1" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" 370 | dependencies = [ 371 | "crossbeam-deque", 372 | "crossbeam-utils", 373 | ] 374 | 375 | [[package]] 376 | name = "scoped_threadpool" 377 | version = "0.1.9" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" 380 | 381 | [[package]] 382 | name = "syn" 383 | version = "2.0.76" 384 | source = "registry+https://github.com/rust-lang/crates.io-index" 385 | checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" 386 | dependencies = [ 387 | "proc-macro2", 388 | "quote", 389 | "unicode-ident", 390 | ] 391 | 392 | [[package]] 393 | name = "tiff" 394 | version = "0.6.1" 395 | source = "registry+https://github.com/rust-lang/crates.io-index" 396 | checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" 397 | dependencies = [ 398 | "jpeg-decoder", 399 | "miniz_oxide 0.4.4", 400 | "weezl", 401 | ] 402 | 403 | [[package]] 404 | name = "unicode-ident" 405 | version = "1.0.12" 406 | source = "registry+https://github.com/rust-lang/crates.io-index" 407 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 408 | 409 | [[package]] 410 | name = "weezl" 411 | version = "0.1.8" 412 | source = "registry+https://github.com/rust-lang/crates.io-index" 413 | checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" 414 | -------------------------------------------------------------------------------- /databases/diesel_mysql/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "bitflags" 7 | version = "2.7.0" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be" 10 | 11 | [[package]] 12 | name = "byteorder" 13 | version = "1.5.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" 16 | 17 | [[package]] 18 | name = "darling" 19 | version = "0.20.10" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" 22 | dependencies = [ 23 | "darling_core", 24 | "darling_macro", 25 | ] 26 | 27 | [[package]] 28 | name = "darling_core" 29 | version = "0.20.10" 30 | source = "registry+https://github.com/rust-lang/crates.io-index" 31 | checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" 32 | dependencies = [ 33 | "fnv", 34 | "ident_case", 35 | "proc-macro2", 36 | "quote", 37 | "strsim", 38 | "syn", 39 | ] 40 | 41 | [[package]] 42 | name = "darling_macro" 43 | version = "0.20.10" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" 46 | dependencies = [ 47 | "darling_core", 48 | "quote", 49 | "syn", 50 | ] 51 | 52 | [[package]] 53 | name = "diesel" 54 | version = "2.2.6" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "ccf1bedf64cdb9643204a36dd15b19a6ce8e7aa7f7b105868e9f1fad5ffa7d12" 57 | dependencies = [ 58 | "bitflags", 59 | "byteorder", 60 | "diesel_derives", 61 | "mysqlclient-sys", 62 | "percent-encoding", 63 | "url", 64 | ] 65 | 66 | [[package]] 67 | name = "diesel_derives" 68 | version = "2.2.3" 69 | source = "registry+https://github.com/rust-lang/crates.io-index" 70 | checksum = "e7f2c3de51e2ba6bf2a648285696137aaf0f5f487bcbea93972fe8a364e131a4" 71 | dependencies = [ 72 | "diesel_table_macro_syntax", 73 | "dsl_auto_type", 74 | "proc-macro2", 75 | "quote", 76 | "syn", 77 | ] 78 | 79 | [[package]] 80 | name = "diesel_mysql" 81 | version = "0.1.0" 82 | dependencies = [ 83 | "diesel", 84 | "dotenv", 85 | ] 86 | 87 | [[package]] 88 | name = "diesel_table_macro_syntax" 89 | version = "0.2.0" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "209c735641a413bc68c4923a9d6ad4bcb3ca306b794edaa7eb0b3228a99ffb25" 92 | dependencies = [ 93 | "syn", 94 | ] 95 | 96 | [[package]] 97 | name = "displaydoc" 98 | version = "0.2.5" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" 101 | dependencies = [ 102 | "proc-macro2", 103 | "quote", 104 | "syn", 105 | ] 106 | 107 | [[package]] 108 | name = "dotenv" 109 | version = "0.15.0" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" 112 | 113 | [[package]] 114 | name = "dsl_auto_type" 115 | version = "0.1.2" 116 | source = "registry+https://github.com/rust-lang/crates.io-index" 117 | checksum = "c5d9abe6314103864cc2d8901b7ae224e0ab1a103a0a416661b4097b0779b607" 118 | dependencies = [ 119 | "darling", 120 | "either", 121 | "heck", 122 | "proc-macro2", 123 | "quote", 124 | "syn", 125 | ] 126 | 127 | [[package]] 128 | name = "either" 129 | version = "1.13.0" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 132 | 133 | [[package]] 134 | name = "fnv" 135 | version = "1.0.7" 136 | source = "registry+https://github.com/rust-lang/crates.io-index" 137 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 138 | 139 | [[package]] 140 | name = "form_urlencoded" 141 | version = "1.2.1" 142 | source = "registry+https://github.com/rust-lang/crates.io-index" 143 | checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" 144 | dependencies = [ 145 | "percent-encoding", 146 | ] 147 | 148 | [[package]] 149 | name = "heck" 150 | version = "0.5.0" 151 | source = "registry+https://github.com/rust-lang/crates.io-index" 152 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 153 | 154 | [[package]] 155 | name = "icu_collections" 156 | version = "1.5.0" 157 | source = "registry+https://github.com/rust-lang/crates.io-index" 158 | checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" 159 | dependencies = [ 160 | "displaydoc", 161 | "yoke", 162 | "zerofrom", 163 | "zerovec", 164 | ] 165 | 166 | [[package]] 167 | name = "icu_locid" 168 | version = "1.5.0" 169 | source = "registry+https://github.com/rust-lang/crates.io-index" 170 | checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" 171 | dependencies = [ 172 | "displaydoc", 173 | "litemap", 174 | "tinystr", 175 | "writeable", 176 | "zerovec", 177 | ] 178 | 179 | [[package]] 180 | name = "icu_locid_transform" 181 | version = "1.5.0" 182 | source = "registry+https://github.com/rust-lang/crates.io-index" 183 | checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" 184 | dependencies = [ 185 | "displaydoc", 186 | "icu_locid", 187 | "icu_locid_transform_data", 188 | "icu_provider", 189 | "tinystr", 190 | "zerovec", 191 | ] 192 | 193 | [[package]] 194 | name = "icu_locid_transform_data" 195 | version = "1.5.0" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" 198 | 199 | [[package]] 200 | name = "icu_normalizer" 201 | version = "1.5.0" 202 | source = "registry+https://github.com/rust-lang/crates.io-index" 203 | checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" 204 | dependencies = [ 205 | "displaydoc", 206 | "icu_collections", 207 | "icu_normalizer_data", 208 | "icu_properties", 209 | "icu_provider", 210 | "smallvec", 211 | "utf16_iter", 212 | "utf8_iter", 213 | "write16", 214 | "zerovec", 215 | ] 216 | 217 | [[package]] 218 | name = "icu_normalizer_data" 219 | version = "1.5.0" 220 | source = "registry+https://github.com/rust-lang/crates.io-index" 221 | checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" 222 | 223 | [[package]] 224 | name = "icu_properties" 225 | version = "1.5.1" 226 | source = "registry+https://github.com/rust-lang/crates.io-index" 227 | checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" 228 | dependencies = [ 229 | "displaydoc", 230 | "icu_collections", 231 | "icu_locid_transform", 232 | "icu_properties_data", 233 | "icu_provider", 234 | "tinystr", 235 | "zerovec", 236 | ] 237 | 238 | [[package]] 239 | name = "icu_properties_data" 240 | version = "1.5.0" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" 243 | 244 | [[package]] 245 | name = "icu_provider" 246 | version = "1.5.0" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" 249 | dependencies = [ 250 | "displaydoc", 251 | "icu_locid", 252 | "icu_provider_macros", 253 | "stable_deref_trait", 254 | "tinystr", 255 | "writeable", 256 | "yoke", 257 | "zerofrom", 258 | "zerovec", 259 | ] 260 | 261 | [[package]] 262 | name = "icu_provider_macros" 263 | version = "1.5.0" 264 | source = "registry+https://github.com/rust-lang/crates.io-index" 265 | checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" 266 | dependencies = [ 267 | "proc-macro2", 268 | "quote", 269 | "syn", 270 | ] 271 | 272 | [[package]] 273 | name = "ident_case" 274 | version = "1.0.1" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 277 | 278 | [[package]] 279 | name = "idna" 280 | version = "1.0.3" 281 | source = "registry+https://github.com/rust-lang/crates.io-index" 282 | checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" 283 | dependencies = [ 284 | "idna_adapter", 285 | "smallvec", 286 | "utf8_iter", 287 | ] 288 | 289 | [[package]] 290 | name = "idna_adapter" 291 | version = "1.2.0" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" 294 | dependencies = [ 295 | "icu_normalizer", 296 | "icu_properties", 297 | ] 298 | 299 | [[package]] 300 | name = "litemap" 301 | version = "0.7.4" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" 304 | 305 | [[package]] 306 | name = "mysqlclient-sys" 307 | version = "0.4.2" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "6bbb9b017b98c4cde5802998113e182eecc1ebce8d47e9ea1697b9a623d53870" 310 | dependencies = [ 311 | "pkg-config", 312 | "vcpkg", 313 | ] 314 | 315 | [[package]] 316 | name = "percent-encoding" 317 | version = "2.3.1" 318 | source = "registry+https://github.com/rust-lang/crates.io-index" 319 | checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 320 | 321 | [[package]] 322 | name = "pkg-config" 323 | version = "0.3.31" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" 326 | 327 | [[package]] 328 | name = "proc-macro2" 329 | version = "1.0.93" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" 332 | dependencies = [ 333 | "unicode-ident", 334 | ] 335 | 336 | [[package]] 337 | name = "quote" 338 | version = "1.0.38" 339 | source = "registry+https://github.com/rust-lang/crates.io-index" 340 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 341 | dependencies = [ 342 | "proc-macro2", 343 | ] 344 | 345 | [[package]] 346 | name = "serde" 347 | version = "1.0.217" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" 350 | dependencies = [ 351 | "serde_derive", 352 | ] 353 | 354 | [[package]] 355 | name = "serde_derive" 356 | version = "1.0.217" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" 359 | dependencies = [ 360 | "proc-macro2", 361 | "quote", 362 | "syn", 363 | ] 364 | 365 | [[package]] 366 | name = "smallvec" 367 | version = "1.13.2" 368 | source = "registry+https://github.com/rust-lang/crates.io-index" 369 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 370 | 371 | [[package]] 372 | name = "stable_deref_trait" 373 | version = "1.2.0" 374 | source = "registry+https://github.com/rust-lang/crates.io-index" 375 | checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" 376 | 377 | [[package]] 378 | name = "strsim" 379 | version = "0.11.1" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 382 | 383 | [[package]] 384 | name = "syn" 385 | version = "2.0.96" 386 | source = "registry+https://github.com/rust-lang/crates.io-index" 387 | checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" 388 | dependencies = [ 389 | "proc-macro2", 390 | "quote", 391 | "unicode-ident", 392 | ] 393 | 394 | [[package]] 395 | name = "synstructure" 396 | version = "0.13.1" 397 | source = "registry+https://github.com/rust-lang/crates.io-index" 398 | checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" 399 | dependencies = [ 400 | "proc-macro2", 401 | "quote", 402 | "syn", 403 | ] 404 | 405 | [[package]] 406 | name = "tinystr" 407 | version = "0.7.6" 408 | source = "registry+https://github.com/rust-lang/crates.io-index" 409 | checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" 410 | dependencies = [ 411 | "displaydoc", 412 | "zerovec", 413 | ] 414 | 415 | [[package]] 416 | name = "unicode-ident" 417 | version = "1.0.14" 418 | source = "registry+https://github.com/rust-lang/crates.io-index" 419 | checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" 420 | 421 | [[package]] 422 | name = "url" 423 | version = "2.5.4" 424 | source = "registry+https://github.com/rust-lang/crates.io-index" 425 | checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" 426 | dependencies = [ 427 | "form_urlencoded", 428 | "idna", 429 | "percent-encoding", 430 | ] 431 | 432 | [[package]] 433 | name = "utf16_iter" 434 | version = "1.0.5" 435 | source = "registry+https://github.com/rust-lang/crates.io-index" 436 | checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" 437 | 438 | [[package]] 439 | name = "utf8_iter" 440 | version = "1.0.4" 441 | source = "registry+https://github.com/rust-lang/crates.io-index" 442 | checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" 443 | 444 | [[package]] 445 | name = "vcpkg" 446 | version = "0.2.15" 447 | source = "registry+https://github.com/rust-lang/crates.io-index" 448 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 449 | 450 | [[package]] 451 | name = "write16" 452 | version = "1.0.0" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" 455 | 456 | [[package]] 457 | name = "writeable" 458 | version = "0.5.5" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" 461 | 462 | [[package]] 463 | name = "yoke" 464 | version = "0.7.5" 465 | source = "registry+https://github.com/rust-lang/crates.io-index" 466 | checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" 467 | dependencies = [ 468 | "serde", 469 | "stable_deref_trait", 470 | "yoke-derive", 471 | "zerofrom", 472 | ] 473 | 474 | [[package]] 475 | name = "yoke-derive" 476 | version = "0.7.5" 477 | source = "registry+https://github.com/rust-lang/crates.io-index" 478 | checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" 479 | dependencies = [ 480 | "proc-macro2", 481 | "quote", 482 | "syn", 483 | "synstructure", 484 | ] 485 | 486 | [[package]] 487 | name = "zerofrom" 488 | version = "0.1.5" 489 | source = "registry+https://github.com/rust-lang/crates.io-index" 490 | checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" 491 | dependencies = [ 492 | "zerofrom-derive", 493 | ] 494 | 495 | [[package]] 496 | name = "zerofrom-derive" 497 | version = "0.1.5" 498 | source = "registry+https://github.com/rust-lang/crates.io-index" 499 | checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" 500 | dependencies = [ 501 | "proc-macro2", 502 | "quote", 503 | "syn", 504 | "synstructure", 505 | ] 506 | 507 | [[package]] 508 | name = "zerovec" 509 | version = "0.10.4" 510 | source = "registry+https://github.com/rust-lang/crates.io-index" 511 | checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" 512 | dependencies = [ 513 | "yoke", 514 | "zerofrom", 515 | "zerovec-derive", 516 | ] 517 | 518 | [[package]] 519 | name = "zerovec-derive" 520 | version = "0.10.3" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" 523 | dependencies = [ 524 | "proc-macro2", 525 | "quote", 526 | "syn", 527 | ] 528 | --------------------------------------------------------------------------------