├── .gitignore ├── README.md ├── rust-azure-functions ├── .DS_Store ├── .cargo │ └── config ├── .funcignore ├── .gitignore ├── .vscode │ └── extensions.json ├── Cargo.lock ├── Cargo.toml ├── HttpExample │ └── function.json ├── handler ├── host.json ├── local.settings.json └── src │ └── main.rs └── rust-lambda ├── .github └── workflows │ └── build-rust.yaml ├── Cargo.lock ├── Cargo.toml └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # serverless-rust 2 | 3 | Examples to run Rust based workloads on 4 | 5 | - Azure Functions 6 | - AWS Lambda 7 | -------------------------------------------------------------------------------- /rust-azure-functions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddprrt/serverless-rust/78ad06d6d21fdedfb53a56660391788082da7a44/rust-azure-functions/.DS_Store -------------------------------------------------------------------------------- /rust-azure-functions/.cargo/config: -------------------------------------------------------------------------------- 1 | [target.x86_64-unknown-linux-musl] 2 | linker = "rust-lld" 3 | -------------------------------------------------------------------------------- /rust-azure-functions/.funcignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /rust-azure-functions/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rust-azure-functions/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "ms-azuretools.vscode-azurefunctions" 4 | ] 5 | } -------------------------------------------------------------------------------- /rust-azure-functions/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 = "autocfg" 7 | version = "1.0.1" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 10 | 11 | [[package]] 12 | name = "base64" 13 | version = "0.13.0" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 16 | 17 | [[package]] 18 | name = "bitflags" 19 | version = "1.2.1" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 22 | 23 | [[package]] 24 | name = "block-buffer" 25 | version = "0.9.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" 28 | dependencies = [ 29 | "generic-array", 30 | ] 31 | 32 | [[package]] 33 | name = "buf_redux" 34 | version = "0.8.4" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" 37 | dependencies = [ 38 | "memchr", 39 | "safemem", 40 | ] 41 | 42 | [[package]] 43 | name = "byteorder" 44 | version = "1.4.3" 45 | source = "registry+https://github.com/rust-lang/crates.io-index" 46 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 47 | 48 | [[package]] 49 | name = "bytes" 50 | version = "1.0.1" 51 | source = "registry+https://github.com/rust-lang/crates.io-index" 52 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" 53 | 54 | [[package]] 55 | name = "cfg-if" 56 | version = "1.0.0" 57 | source = "registry+https://github.com/rust-lang/crates.io-index" 58 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 59 | 60 | [[package]] 61 | name = "cpufeatures" 62 | version = "0.1.1" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" 65 | dependencies = [ 66 | "libc", 67 | ] 68 | 69 | [[package]] 70 | name = "digest" 71 | version = "0.9.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" 74 | dependencies = [ 75 | "generic-array", 76 | ] 77 | 78 | [[package]] 79 | name = "either" 80 | version = "1.6.1" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" 83 | 84 | [[package]] 85 | name = "fnv" 86 | version = "1.0.7" 87 | source = "registry+https://github.com/rust-lang/crates.io-index" 88 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 89 | 90 | [[package]] 91 | name = "form_urlencoded" 92 | version = "1.0.1" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 95 | dependencies = [ 96 | "matches", 97 | "percent-encoding", 98 | ] 99 | 100 | [[package]] 101 | name = "futures" 102 | version = "0.3.15" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "0e7e43a803dae2fa37c1f6a8fe121e1f7bf9548b4dfc0522a42f34145dadfc27" 105 | dependencies = [ 106 | "futures-channel", 107 | "futures-core", 108 | "futures-io", 109 | "futures-sink", 110 | "futures-task", 111 | "futures-util", 112 | ] 113 | 114 | [[package]] 115 | name = "futures-channel" 116 | version = "0.3.15" 117 | source = "registry+https://github.com/rust-lang/crates.io-index" 118 | checksum = "e682a68b29a882df0545c143dc3646daefe80ba479bcdede94d5a703de2871e2" 119 | dependencies = [ 120 | "futures-core", 121 | "futures-sink", 122 | ] 123 | 124 | [[package]] 125 | name = "futures-core" 126 | version = "0.3.15" 127 | source = "registry+https://github.com/rust-lang/crates.io-index" 128 | checksum = "0402f765d8a89a26043b889b26ce3c4679d268fa6bb22cd7c6aad98340e179d1" 129 | 130 | [[package]] 131 | name = "futures-io" 132 | version = "0.3.15" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1" 135 | 136 | [[package]] 137 | name = "futures-sink" 138 | version = "0.3.15" 139 | source = "registry+https://github.com/rust-lang/crates.io-index" 140 | checksum = "a57bead0ceff0d6dde8f465ecd96c9338121bb7717d3e7b108059531870c4282" 141 | 142 | [[package]] 143 | name = "futures-task" 144 | version = "0.3.15" 145 | source = "registry+https://github.com/rust-lang/crates.io-index" 146 | checksum = "8a16bef9fc1a4dddb5bee51c989e3fbba26569cbb0e31f5b303c184e3dd33dae" 147 | 148 | [[package]] 149 | name = "futures-util" 150 | version = "0.3.15" 151 | source = "registry+https://github.com/rust-lang/crates.io-index" 152 | checksum = "feb5c238d27e2bf94ffdfd27b2c29e3df4a68c4193bb6427384259e2bf191967" 153 | dependencies = [ 154 | "autocfg", 155 | "futures-core", 156 | "futures-sink", 157 | "futures-task", 158 | "pin-project-lite", 159 | "pin-utils", 160 | "slab", 161 | ] 162 | 163 | [[package]] 164 | name = "generic-array" 165 | version = "0.14.4" 166 | source = "registry+https://github.com/rust-lang/crates.io-index" 167 | checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" 168 | dependencies = [ 169 | "typenum", 170 | "version_check", 171 | ] 172 | 173 | [[package]] 174 | name = "getrandom" 175 | version = "0.1.16" 176 | source = "registry+https://github.com/rust-lang/crates.io-index" 177 | checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" 178 | dependencies = [ 179 | "cfg-if", 180 | "libc", 181 | "wasi 0.9.0+wasi-snapshot-preview1", 182 | ] 183 | 184 | [[package]] 185 | name = "getrandom" 186 | version = "0.2.2" 187 | source = "registry+https://github.com/rust-lang/crates.io-index" 188 | checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" 189 | dependencies = [ 190 | "cfg-if", 191 | "libc", 192 | "wasi 0.10.2+wasi-snapshot-preview1", 193 | ] 194 | 195 | [[package]] 196 | name = "h2" 197 | version = "0.3.3" 198 | source = "registry+https://github.com/rust-lang/crates.io-index" 199 | checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" 200 | dependencies = [ 201 | "bytes", 202 | "fnv", 203 | "futures-core", 204 | "futures-sink", 205 | "futures-util", 206 | "http", 207 | "indexmap", 208 | "slab", 209 | "tokio", 210 | "tokio-util", 211 | "tracing", 212 | ] 213 | 214 | [[package]] 215 | name = "handler" 216 | version = "0.1.0" 217 | dependencies = [ 218 | "itertools", 219 | "num", 220 | "tokio", 221 | "warp", 222 | ] 223 | 224 | [[package]] 225 | name = "hashbrown" 226 | version = "0.9.1" 227 | source = "registry+https://github.com/rust-lang/crates.io-index" 228 | checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" 229 | 230 | [[package]] 231 | name = "headers" 232 | version = "0.3.4" 233 | source = "registry+https://github.com/rust-lang/crates.io-index" 234 | checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" 235 | dependencies = [ 236 | "base64", 237 | "bitflags", 238 | "bytes", 239 | "headers-core", 240 | "http", 241 | "mime", 242 | "sha-1", 243 | "time", 244 | ] 245 | 246 | [[package]] 247 | name = "headers-core" 248 | version = "0.2.0" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" 251 | dependencies = [ 252 | "http", 253 | ] 254 | 255 | [[package]] 256 | name = "hermit-abi" 257 | version = "0.1.18" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" 260 | dependencies = [ 261 | "libc", 262 | ] 263 | 264 | [[package]] 265 | name = "http" 266 | version = "0.2.4" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" 269 | dependencies = [ 270 | "bytes", 271 | "fnv", 272 | "itoa", 273 | ] 274 | 275 | [[package]] 276 | name = "http-body" 277 | version = "0.4.2" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" 280 | dependencies = [ 281 | "bytes", 282 | "http", 283 | "pin-project-lite", 284 | ] 285 | 286 | [[package]] 287 | name = "httparse" 288 | version = "1.4.1" 289 | source = "registry+https://github.com/rust-lang/crates.io-index" 290 | checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" 291 | 292 | [[package]] 293 | name = "httpdate" 294 | version = "1.0.0" 295 | source = "registry+https://github.com/rust-lang/crates.io-index" 296 | checksum = "05842d0d43232b23ccb7060ecb0f0626922c21f30012e97b767b30afd4a5d4b9" 297 | 298 | [[package]] 299 | name = "hyper" 300 | version = "0.14.7" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "1e5f105c494081baa3bf9e200b279e27ec1623895cd504c7dbef8d0b080fcf54" 303 | dependencies = [ 304 | "bytes", 305 | "futures-channel", 306 | "futures-core", 307 | "futures-util", 308 | "h2", 309 | "http", 310 | "http-body", 311 | "httparse", 312 | "httpdate", 313 | "itoa", 314 | "pin-project", 315 | "socket2", 316 | "tokio", 317 | "tower-service", 318 | "tracing", 319 | "want", 320 | ] 321 | 322 | [[package]] 323 | name = "idna" 324 | version = "0.2.3" 325 | source = "registry+https://github.com/rust-lang/crates.io-index" 326 | checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" 327 | dependencies = [ 328 | "matches", 329 | "unicode-bidi", 330 | "unicode-normalization", 331 | ] 332 | 333 | [[package]] 334 | name = "indexmap" 335 | version = "1.6.2" 336 | source = "registry+https://github.com/rust-lang/crates.io-index" 337 | checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" 338 | dependencies = [ 339 | "autocfg", 340 | "hashbrown", 341 | ] 342 | 343 | [[package]] 344 | name = "input_buffer" 345 | version = "0.4.0" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | checksum = "f97967975f448f1a7ddb12b0bc41069d09ed6a1c161a92687e057325db35d413" 348 | dependencies = [ 349 | "bytes", 350 | ] 351 | 352 | [[package]] 353 | name = "itertools" 354 | version = "0.10.1" 355 | source = "registry+https://github.com/rust-lang/crates.io-index" 356 | checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" 357 | dependencies = [ 358 | "either", 359 | ] 360 | 361 | [[package]] 362 | name = "itoa" 363 | version = "0.4.7" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 366 | 367 | [[package]] 368 | name = "lazy_static" 369 | version = "1.4.0" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 372 | 373 | [[package]] 374 | name = "libc" 375 | version = "0.2.94" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" 378 | 379 | [[package]] 380 | name = "log" 381 | version = "0.4.14" 382 | source = "registry+https://github.com/rust-lang/crates.io-index" 383 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 384 | dependencies = [ 385 | "cfg-if", 386 | ] 387 | 388 | [[package]] 389 | name = "matches" 390 | version = "0.1.8" 391 | source = "registry+https://github.com/rust-lang/crates.io-index" 392 | checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" 393 | 394 | [[package]] 395 | name = "memchr" 396 | version = "2.4.0" 397 | source = "registry+https://github.com/rust-lang/crates.io-index" 398 | checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" 399 | 400 | [[package]] 401 | name = "mime" 402 | version = "0.3.16" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" 405 | 406 | [[package]] 407 | name = "mime_guess" 408 | version = "2.0.3" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" 411 | dependencies = [ 412 | "mime", 413 | "unicase", 414 | ] 415 | 416 | [[package]] 417 | name = "mio" 418 | version = "0.7.11" 419 | source = "registry+https://github.com/rust-lang/crates.io-index" 420 | checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" 421 | dependencies = [ 422 | "libc", 423 | "log", 424 | "miow", 425 | "ntapi", 426 | "winapi", 427 | ] 428 | 429 | [[package]] 430 | name = "miow" 431 | version = "0.3.7" 432 | source = "registry+https://github.com/rust-lang/crates.io-index" 433 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 434 | dependencies = [ 435 | "winapi", 436 | ] 437 | 438 | [[package]] 439 | name = "multipart" 440 | version = "0.17.1" 441 | source = "registry+https://github.com/rust-lang/crates.io-index" 442 | checksum = "d050aeedc89243f5347c3e237e3e13dc76fbe4ae3742a57b94dc14f69acf76d4" 443 | dependencies = [ 444 | "buf_redux", 445 | "httparse", 446 | "log", 447 | "mime", 448 | "mime_guess", 449 | "quick-error", 450 | "rand 0.7.3", 451 | "safemem", 452 | "tempfile", 453 | "twoway", 454 | ] 455 | 456 | [[package]] 457 | name = "ntapi" 458 | version = "0.3.6" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 461 | dependencies = [ 462 | "winapi", 463 | ] 464 | 465 | [[package]] 466 | name = "num" 467 | version = "0.4.0" 468 | source = "registry+https://github.com/rust-lang/crates.io-index" 469 | checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" 470 | dependencies = [ 471 | "num-bigint", 472 | "num-complex", 473 | "num-integer", 474 | "num-iter", 475 | "num-rational", 476 | "num-traits", 477 | ] 478 | 479 | [[package]] 480 | name = "num-bigint" 481 | version = "0.4.0" 482 | source = "registry+https://github.com/rust-lang/crates.io-index" 483 | checksum = "4e0d047c1062aa51e256408c560894e5251f08925980e53cf1aa5bd00eec6512" 484 | dependencies = [ 485 | "autocfg", 486 | "num-integer", 487 | "num-traits", 488 | ] 489 | 490 | [[package]] 491 | name = "num-complex" 492 | version = "0.4.0" 493 | source = "registry+https://github.com/rust-lang/crates.io-index" 494 | checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" 495 | dependencies = [ 496 | "num-traits", 497 | ] 498 | 499 | [[package]] 500 | name = "num-integer" 501 | version = "0.1.44" 502 | source = "registry+https://github.com/rust-lang/crates.io-index" 503 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 504 | dependencies = [ 505 | "autocfg", 506 | "num-traits", 507 | ] 508 | 509 | [[package]] 510 | name = "num-iter" 511 | version = "0.1.42" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" 514 | dependencies = [ 515 | "autocfg", 516 | "num-integer", 517 | "num-traits", 518 | ] 519 | 520 | [[package]] 521 | name = "num-rational" 522 | version = "0.4.0" 523 | source = "registry+https://github.com/rust-lang/crates.io-index" 524 | checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" 525 | dependencies = [ 526 | "autocfg", 527 | "num-bigint", 528 | "num-integer", 529 | "num-traits", 530 | ] 531 | 532 | [[package]] 533 | name = "num-traits" 534 | version = "0.2.14" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 537 | dependencies = [ 538 | "autocfg", 539 | ] 540 | 541 | [[package]] 542 | name = "num_cpus" 543 | version = "1.13.0" 544 | source = "registry+https://github.com/rust-lang/crates.io-index" 545 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 546 | dependencies = [ 547 | "hermit-abi", 548 | "libc", 549 | ] 550 | 551 | [[package]] 552 | name = "opaque-debug" 553 | version = "0.3.0" 554 | source = "registry+https://github.com/rust-lang/crates.io-index" 555 | checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" 556 | 557 | [[package]] 558 | name = "percent-encoding" 559 | version = "2.1.0" 560 | source = "registry+https://github.com/rust-lang/crates.io-index" 561 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 562 | 563 | [[package]] 564 | name = "pin-project" 565 | version = "1.0.7" 566 | source = "registry+https://github.com/rust-lang/crates.io-index" 567 | checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4" 568 | dependencies = [ 569 | "pin-project-internal", 570 | ] 571 | 572 | [[package]] 573 | name = "pin-project-internal" 574 | version = "1.0.7" 575 | source = "registry+https://github.com/rust-lang/crates.io-index" 576 | checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f" 577 | dependencies = [ 578 | "proc-macro2", 579 | "quote", 580 | "syn", 581 | ] 582 | 583 | [[package]] 584 | name = "pin-project-lite" 585 | version = "0.2.6" 586 | source = "registry+https://github.com/rust-lang/crates.io-index" 587 | checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" 588 | 589 | [[package]] 590 | name = "pin-utils" 591 | version = "0.1.0" 592 | source = "registry+https://github.com/rust-lang/crates.io-index" 593 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 594 | 595 | [[package]] 596 | name = "ppv-lite86" 597 | version = "0.2.10" 598 | source = "registry+https://github.com/rust-lang/crates.io-index" 599 | checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" 600 | 601 | [[package]] 602 | name = "proc-macro2" 603 | version = "1.0.26" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" 606 | dependencies = [ 607 | "unicode-xid", 608 | ] 609 | 610 | [[package]] 611 | name = "quick-error" 612 | version = "1.2.3" 613 | source = "registry+https://github.com/rust-lang/crates.io-index" 614 | checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" 615 | 616 | [[package]] 617 | name = "quote" 618 | version = "1.0.9" 619 | source = "registry+https://github.com/rust-lang/crates.io-index" 620 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 621 | dependencies = [ 622 | "proc-macro2", 623 | ] 624 | 625 | [[package]] 626 | name = "rand" 627 | version = "0.7.3" 628 | source = "registry+https://github.com/rust-lang/crates.io-index" 629 | checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" 630 | dependencies = [ 631 | "getrandom 0.1.16", 632 | "libc", 633 | "rand_chacha 0.2.2", 634 | "rand_core 0.5.1", 635 | "rand_hc 0.2.0", 636 | ] 637 | 638 | [[package]] 639 | name = "rand" 640 | version = "0.8.3" 641 | source = "registry+https://github.com/rust-lang/crates.io-index" 642 | checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" 643 | dependencies = [ 644 | "libc", 645 | "rand_chacha 0.3.0", 646 | "rand_core 0.6.2", 647 | "rand_hc 0.3.0", 648 | ] 649 | 650 | [[package]] 651 | name = "rand_chacha" 652 | version = "0.2.2" 653 | source = "registry+https://github.com/rust-lang/crates.io-index" 654 | checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" 655 | dependencies = [ 656 | "ppv-lite86", 657 | "rand_core 0.5.1", 658 | ] 659 | 660 | [[package]] 661 | name = "rand_chacha" 662 | version = "0.3.0" 663 | source = "registry+https://github.com/rust-lang/crates.io-index" 664 | checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" 665 | dependencies = [ 666 | "ppv-lite86", 667 | "rand_core 0.6.2", 668 | ] 669 | 670 | [[package]] 671 | name = "rand_core" 672 | version = "0.5.1" 673 | source = "registry+https://github.com/rust-lang/crates.io-index" 674 | checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" 675 | dependencies = [ 676 | "getrandom 0.1.16", 677 | ] 678 | 679 | [[package]] 680 | name = "rand_core" 681 | version = "0.6.2" 682 | source = "registry+https://github.com/rust-lang/crates.io-index" 683 | checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" 684 | dependencies = [ 685 | "getrandom 0.2.2", 686 | ] 687 | 688 | [[package]] 689 | name = "rand_hc" 690 | version = "0.2.0" 691 | source = "registry+https://github.com/rust-lang/crates.io-index" 692 | checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" 693 | dependencies = [ 694 | "rand_core 0.5.1", 695 | ] 696 | 697 | [[package]] 698 | name = "rand_hc" 699 | version = "0.3.0" 700 | source = "registry+https://github.com/rust-lang/crates.io-index" 701 | checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" 702 | dependencies = [ 703 | "rand_core 0.6.2", 704 | ] 705 | 706 | [[package]] 707 | name = "redox_syscall" 708 | version = "0.2.8" 709 | source = "registry+https://github.com/rust-lang/crates.io-index" 710 | checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc" 711 | dependencies = [ 712 | "bitflags", 713 | ] 714 | 715 | [[package]] 716 | name = "remove_dir_all" 717 | version = "0.5.3" 718 | source = "registry+https://github.com/rust-lang/crates.io-index" 719 | checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" 720 | dependencies = [ 721 | "winapi", 722 | ] 723 | 724 | [[package]] 725 | name = "ryu" 726 | version = "1.0.5" 727 | source = "registry+https://github.com/rust-lang/crates.io-index" 728 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 729 | 730 | [[package]] 731 | name = "safemem" 732 | version = "0.3.3" 733 | source = "registry+https://github.com/rust-lang/crates.io-index" 734 | checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" 735 | 736 | [[package]] 737 | name = "scoped-tls" 738 | version = "1.0.0" 739 | source = "registry+https://github.com/rust-lang/crates.io-index" 740 | checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" 741 | 742 | [[package]] 743 | name = "serde" 744 | version = "1.0.125" 745 | source = "registry+https://github.com/rust-lang/crates.io-index" 746 | checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" 747 | 748 | [[package]] 749 | name = "serde_json" 750 | version = "1.0.64" 751 | source = "registry+https://github.com/rust-lang/crates.io-index" 752 | checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" 753 | dependencies = [ 754 | "itoa", 755 | "ryu", 756 | "serde", 757 | ] 758 | 759 | [[package]] 760 | name = "serde_urlencoded" 761 | version = "0.7.0" 762 | source = "registry+https://github.com/rust-lang/crates.io-index" 763 | checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" 764 | dependencies = [ 765 | "form_urlencoded", 766 | "itoa", 767 | "ryu", 768 | "serde", 769 | ] 770 | 771 | [[package]] 772 | name = "sha-1" 773 | version = "0.9.5" 774 | source = "registry+https://github.com/rust-lang/crates.io-index" 775 | checksum = "b659df5fc3ce22274daac600ffb845300bd2125bcfaec047823075afdab81c00" 776 | dependencies = [ 777 | "block-buffer", 778 | "cfg-if", 779 | "cpufeatures", 780 | "digest", 781 | "opaque-debug", 782 | ] 783 | 784 | [[package]] 785 | name = "slab" 786 | version = "0.4.3" 787 | source = "registry+https://github.com/rust-lang/crates.io-index" 788 | checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" 789 | 790 | [[package]] 791 | name = "socket2" 792 | version = "0.4.0" 793 | source = "registry+https://github.com/rust-lang/crates.io-index" 794 | checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" 795 | dependencies = [ 796 | "libc", 797 | "winapi", 798 | ] 799 | 800 | [[package]] 801 | name = "syn" 802 | version = "1.0.72" 803 | source = "registry+https://github.com/rust-lang/crates.io-index" 804 | checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" 805 | dependencies = [ 806 | "proc-macro2", 807 | "quote", 808 | "unicode-xid", 809 | ] 810 | 811 | [[package]] 812 | name = "tempfile" 813 | version = "3.2.0" 814 | source = "registry+https://github.com/rust-lang/crates.io-index" 815 | checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" 816 | dependencies = [ 817 | "cfg-if", 818 | "libc", 819 | "rand 0.8.3", 820 | "redox_syscall", 821 | "remove_dir_all", 822 | "winapi", 823 | ] 824 | 825 | [[package]] 826 | name = "time" 827 | version = "0.1.43" 828 | source = "registry+https://github.com/rust-lang/crates.io-index" 829 | checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" 830 | dependencies = [ 831 | "libc", 832 | "winapi", 833 | ] 834 | 835 | [[package]] 836 | name = "tinyvec" 837 | version = "1.2.0" 838 | source = "registry+https://github.com/rust-lang/crates.io-index" 839 | checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" 840 | dependencies = [ 841 | "tinyvec_macros", 842 | ] 843 | 844 | [[package]] 845 | name = "tinyvec_macros" 846 | version = "0.1.0" 847 | source = "registry+https://github.com/rust-lang/crates.io-index" 848 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 849 | 850 | [[package]] 851 | name = "tokio" 852 | version = "1.5.0" 853 | source = "registry+https://github.com/rust-lang/crates.io-index" 854 | checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" 855 | dependencies = [ 856 | "autocfg", 857 | "bytes", 858 | "libc", 859 | "memchr", 860 | "mio", 861 | "num_cpus", 862 | "pin-project-lite", 863 | "tokio-macros", 864 | ] 865 | 866 | [[package]] 867 | name = "tokio-macros" 868 | version = "1.1.0" 869 | source = "registry+https://github.com/rust-lang/crates.io-index" 870 | checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" 871 | dependencies = [ 872 | "proc-macro2", 873 | "quote", 874 | "syn", 875 | ] 876 | 877 | [[package]] 878 | name = "tokio-stream" 879 | version = "0.1.5" 880 | source = "registry+https://github.com/rust-lang/crates.io-index" 881 | checksum = "e177a5d8c3bf36de9ebe6d58537d8879e964332f93fb3339e43f618c81361af0" 882 | dependencies = [ 883 | "futures-core", 884 | "pin-project-lite", 885 | "tokio", 886 | ] 887 | 888 | [[package]] 889 | name = "tokio-tungstenite" 890 | version = "0.13.0" 891 | source = "registry+https://github.com/rust-lang/crates.io-index" 892 | checksum = "e1a5f475f1b9d077ea1017ecbc60890fda8e54942d680ca0b1d2b47cfa2d861b" 893 | dependencies = [ 894 | "futures-util", 895 | "log", 896 | "pin-project", 897 | "tokio", 898 | "tungstenite", 899 | ] 900 | 901 | [[package]] 902 | name = "tokio-util" 903 | version = "0.6.6" 904 | source = "registry+https://github.com/rust-lang/crates.io-index" 905 | checksum = "940a12c99365c31ea8dd9ba04ec1be183ffe4920102bb7122c2f515437601e8e" 906 | dependencies = [ 907 | "bytes", 908 | "futures-core", 909 | "futures-sink", 910 | "log", 911 | "pin-project-lite", 912 | "tokio", 913 | ] 914 | 915 | [[package]] 916 | name = "tower-service" 917 | version = "0.3.1" 918 | source = "registry+https://github.com/rust-lang/crates.io-index" 919 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" 920 | 921 | [[package]] 922 | name = "tracing" 923 | version = "0.1.26" 924 | source = "registry+https://github.com/rust-lang/crates.io-index" 925 | checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" 926 | dependencies = [ 927 | "cfg-if", 928 | "log", 929 | "pin-project-lite", 930 | "tracing-core", 931 | ] 932 | 933 | [[package]] 934 | name = "tracing-core" 935 | version = "0.1.18" 936 | source = "registry+https://github.com/rust-lang/crates.io-index" 937 | checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" 938 | dependencies = [ 939 | "lazy_static", 940 | ] 941 | 942 | [[package]] 943 | name = "try-lock" 944 | version = "0.2.3" 945 | source = "registry+https://github.com/rust-lang/crates.io-index" 946 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" 947 | 948 | [[package]] 949 | name = "tungstenite" 950 | version = "0.12.0" 951 | source = "registry+https://github.com/rust-lang/crates.io-index" 952 | checksum = "8ada8297e8d70872fa9a551d93250a9f407beb9f37ef86494eb20012a2ff7c24" 953 | dependencies = [ 954 | "base64", 955 | "byteorder", 956 | "bytes", 957 | "http", 958 | "httparse", 959 | "input_buffer", 960 | "log", 961 | "rand 0.8.3", 962 | "sha-1", 963 | "url", 964 | "utf-8", 965 | ] 966 | 967 | [[package]] 968 | name = "twoway" 969 | version = "0.1.8" 970 | source = "registry+https://github.com/rust-lang/crates.io-index" 971 | checksum = "59b11b2b5241ba34be09c3cc85a36e56e48f9888862e19cedf23336d35316ed1" 972 | dependencies = [ 973 | "memchr", 974 | ] 975 | 976 | [[package]] 977 | name = "typenum" 978 | version = "1.13.0" 979 | source = "registry+https://github.com/rust-lang/crates.io-index" 980 | checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" 981 | 982 | [[package]] 983 | name = "unicase" 984 | version = "2.6.0" 985 | source = "registry+https://github.com/rust-lang/crates.io-index" 986 | checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" 987 | dependencies = [ 988 | "version_check", 989 | ] 990 | 991 | [[package]] 992 | name = "unicode-bidi" 993 | version = "0.3.5" 994 | source = "registry+https://github.com/rust-lang/crates.io-index" 995 | checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" 996 | dependencies = [ 997 | "matches", 998 | ] 999 | 1000 | [[package]] 1001 | name = "unicode-normalization" 1002 | version = "0.1.17" 1003 | source = "registry+https://github.com/rust-lang/crates.io-index" 1004 | checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" 1005 | dependencies = [ 1006 | "tinyvec", 1007 | ] 1008 | 1009 | [[package]] 1010 | name = "unicode-xid" 1011 | version = "0.2.2" 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" 1013 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 1014 | 1015 | [[package]] 1016 | name = "url" 1017 | version = "2.2.2" 1018 | source = "registry+https://github.com/rust-lang/crates.io-index" 1019 | checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" 1020 | dependencies = [ 1021 | "form_urlencoded", 1022 | "idna", 1023 | "matches", 1024 | "percent-encoding", 1025 | ] 1026 | 1027 | [[package]] 1028 | name = "utf-8" 1029 | version = "0.7.6" 1030 | source = "registry+https://github.com/rust-lang/crates.io-index" 1031 | checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" 1032 | 1033 | [[package]] 1034 | name = "version_check" 1035 | version = "0.9.3" 1036 | source = "registry+https://github.com/rust-lang/crates.io-index" 1037 | checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" 1038 | 1039 | [[package]] 1040 | name = "want" 1041 | version = "0.3.0" 1042 | source = "registry+https://github.com/rust-lang/crates.io-index" 1043 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 1044 | dependencies = [ 1045 | "log", 1046 | "try-lock", 1047 | ] 1048 | 1049 | [[package]] 1050 | name = "warp" 1051 | version = "0.3.1" 1052 | source = "registry+https://github.com/rust-lang/crates.io-index" 1053 | checksum = "332d47745e9a0c38636dbd454729b147d16bd1ed08ae67b3ab281c4506771054" 1054 | dependencies = [ 1055 | "bytes", 1056 | "futures", 1057 | "headers", 1058 | "http", 1059 | "hyper", 1060 | "log", 1061 | "mime", 1062 | "mime_guess", 1063 | "multipart", 1064 | "percent-encoding", 1065 | "pin-project", 1066 | "scoped-tls", 1067 | "serde", 1068 | "serde_json", 1069 | "serde_urlencoded", 1070 | "tokio", 1071 | "tokio-stream", 1072 | "tokio-tungstenite", 1073 | "tokio-util", 1074 | "tower-service", 1075 | "tracing", 1076 | ] 1077 | 1078 | [[package]] 1079 | name = "wasi" 1080 | version = "0.9.0+wasi-snapshot-preview1" 1081 | source = "registry+https://github.com/rust-lang/crates.io-index" 1082 | checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" 1083 | 1084 | [[package]] 1085 | name = "wasi" 1086 | version = "0.10.2+wasi-snapshot-preview1" 1087 | source = "registry+https://github.com/rust-lang/crates.io-index" 1088 | checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" 1089 | 1090 | [[package]] 1091 | name = "winapi" 1092 | version = "0.3.9" 1093 | source = "registry+https://github.com/rust-lang/crates.io-index" 1094 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1095 | dependencies = [ 1096 | "winapi-i686-pc-windows-gnu", 1097 | "winapi-x86_64-pc-windows-gnu", 1098 | ] 1099 | 1100 | [[package]] 1101 | name = "winapi-i686-pc-windows-gnu" 1102 | version = "0.4.0" 1103 | source = "registry+https://github.com/rust-lang/crates.io-index" 1104 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1105 | 1106 | [[package]] 1107 | name = "winapi-x86_64-pc-windows-gnu" 1108 | version = "0.4.0" 1109 | source = "registry+https://github.com/rust-lang/crates.io-index" 1110 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1111 | -------------------------------------------------------------------------------- /rust-azure-functions/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "handler" 3 | version = "0.1.0" 4 | authors = ["stefan.baumgartner "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | warp = "0.3" 11 | tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] } 12 | itertools = "0.10.1" 13 | num = "0.4.0" 14 | 15 | 16 | [[bin]] 17 | name = "handler" 18 | path = "src/main.rs" 19 | 20 | [profile.release] 21 | opt-level = 3 22 | lto = true 23 | -------------------------------------------------------------------------------- /rust-azure-functions/HttpExample/function.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindings": [ 3 | { 4 | "authLevel": "anonymous", 5 | "type": "httpTrigger", 6 | "direction": "in", 7 | "name": "req", 8 | "methods": [ 9 | "get", 10 | "post" 11 | ] 12 | }, 13 | { 14 | "type": "http", 15 | "direction": "out", 16 | "name": "res" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /rust-azure-functions/handler: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ddprrt/serverless-rust/78ad06d6d21fdedfb53a56660391788082da7a44/rust-azure-functions/handler -------------------------------------------------------------------------------- /rust-azure-functions/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | }, 11 | "extensionBundle": { 12 | "id": "Microsoft.Azure.Functions.ExtensionBundle", 13 | "version": "[2.*, 3.0.0)" 14 | }, 15 | "customHandler": { 16 | "description": { 17 | "defaultExecutablePath": "handler", 18 | "workingDirectory": "", 19 | "arguments": [] 20 | }, 21 | "enableForwardingHttpRequest": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rust-azure-functions/local.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "IsEncrypted": false, 3 | "Values": { 4 | "FUNCTIONS_WORKER_RUNTIME": "custom", 5 | "AzureWebJobsStorage": "" 6 | } 7 | } -------------------------------------------------------------------------------- /rust-azure-functions/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::{HashMap, HashSet}}; 2 | use std::env; 3 | use std::net::Ipv4Addr; 4 | use warp::{http::Response, Filter}; 5 | 6 | use itertools::Itertools; 7 | use num::{FromPrimitive, Integer}; 8 | 9 | 10 | #[derive(Debug, PartialEq, Eq)] 11 | pub struct Palindrome { 12 | factors: HashSet<(u64, u64)>, 13 | value: u64, 14 | } 15 | 16 | impl Palindrome { 17 | pub fn new(a: u64, b: u64) -> Palindrome { 18 | let mut set: HashSet<(u64, u64)> = HashSet::new(); 19 | set.insert((a, b)); 20 | Self { 21 | value: a * b, 22 | factors: set, 23 | } 24 | } 25 | 26 | pub fn value(&self) -> u64 { 27 | self.value 28 | } 29 | 30 | pub fn insert(&mut self, a: u64, b: u64) { 31 | self.factors.insert((a, b)); 32 | } 33 | } 34 | 35 | fn is_palindrome(a: u64, b: u64) -> bool { 36 | let prod = a * b; 37 | prod == reverse(prod) 38 | } 39 | 40 | /// Reverses an unsigned integer number (e.g. 123 -> 321) 41 | fn reverse(a: T) -> T { 42 | let radix = FromPrimitive::from_usize(10).unwrap(); 43 | let mut n = a; 44 | let mut reversed = FromPrimitive::from_usize(0).unwrap(); 45 | 46 | while !n.is_zero() { 47 | reversed = reversed * radix + n % radix; 48 | n = n / radix; 49 | } 50 | 51 | reversed 52 | } 53 | 54 | fn check_palindrom(map: &mut HashMap, a: u64, b: u64) { 55 | if is_palindrome(a, b) { 56 | let prod = a * b; 57 | map.entry(prod) 58 | .or_insert_with(|| Palindrome::new(a, b)) 59 | .insert(a, b); 60 | } 61 | } 62 | 63 | pub fn palindrome_products(min: u64, max: u64) -> Option<(Palindrome, Palindrome)> { 64 | let mut map: HashMap = HashMap::new(); 65 | 66 | for (a, b) in (min..=max).tuple_combinations() { 67 | check_palindrom(&mut map, a, b); 68 | } 69 | for c in min..=max { 70 | check_palindrom(&mut map, c, c); 71 | } 72 | 73 | let prod_min_max = map.keys().minmax().into_option(); 74 | 75 | if let Some((i, j)) = prod_min_max { 76 | let (i, j) = (i.to_owned(), j.to_owned()); 77 | Some((map.remove(&i).unwrap(), map.remove(&j).unwrap())) 78 | } else { 79 | None 80 | } 81 | } 82 | 83 | 84 | #[tokio::main] 85 | async fn main() { 86 | let example1 = warp::get() 87 | .and(warp::path("api")) 88 | .and(warp::path("httpexample")) 89 | .and(warp::query::>()) 90 | .map(|p: HashMap| match (p.get("min"), p.get("max")) { 91 | (Some(min), Some(max)) => { 92 | let min: u64 = min.parse().unwrap(); 93 | let max: u64 = max.parse().unwrap(); 94 | let val = match palindrome_products(min, max) { 95 | Some((pal_one, pal_two)) => 96 | format!("min {} max {}", pal_one.value, pal_two.value), 97 | None => String::from("Error") 98 | }; 99 | Response::builder().body(val) 100 | }, 101 | _ => Response::builder().body(String::from("Error")) 102 | }); 103 | 104 | let port_key = "FUNCTIONS_CUSTOMHANDLER_PORT"; 105 | let port: u16 = match env::var(port_key) { 106 | Ok(val) => val.parse().expect("Custom Handler port is not a number"), 107 | Err(_) => 3000, 108 | }; 109 | 110 | println!("Starting at {}", port); 111 | 112 | warp::serve(example1) 113 | .run((Ipv4Addr::UNSPECIFIED, port)) 114 | .await 115 | } 116 | -------------------------------------------------------------------------------- /rust-lambda/.github/workflows/build-rust.yaml: -------------------------------------------------------------------------------- 1 | name: GitHub Actions Demo 2 | on: [push] 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | strategy: 7 | matrix: 8 | target: 9 | - x86_64-unknown-linux-gnu 10 | env: 11 | V8_FROM_SOURCE: true 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v1 15 | - name: Install latest Rust toolchain 16 | uses: actions-rs/toolchain@v1 17 | with: 18 | toolchain: stable 19 | target: ${{ matrix.target }} 20 | override: true 21 | - name: Build 22 | uses: actions-rs/cargo@v1 23 | 24 | with: 25 | command: build 26 | args: --release --target=${{ matrix.target }} 27 | - name: Archive production artifacts 28 | uses: actions/upload-artifact@v2 29 | with: 30 | name: dist-${{ matrix.target }} 31 | path: ./target/${{ matrix.target }}/release/bootstrap 32 | -------------------------------------------------------------------------------- /rust-lambda/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 = "async-stream" 7 | version = "0.3.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" 10 | dependencies = [ 11 | "async-stream-impl", 12 | "futures-core", 13 | ] 14 | 15 | [[package]] 16 | name = "async-stream-impl" 17 | version = "0.3.2" 18 | source = "registry+https://github.com/rust-lang/crates.io-index" 19 | checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" 20 | dependencies = [ 21 | "proc-macro2", 22 | "quote", 23 | "syn", 24 | ] 25 | 26 | [[package]] 27 | name = "autocfg" 28 | version = "1.0.1" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 31 | 32 | [[package]] 33 | name = "bytes" 34 | version = "1.0.1" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" 37 | 38 | [[package]] 39 | name = "cfg-if" 40 | version = "1.0.0" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 43 | 44 | [[package]] 45 | name = "either" 46 | version = "1.6.1" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" 49 | 50 | [[package]] 51 | name = "fnv" 52 | version = "1.0.7" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 55 | 56 | [[package]] 57 | name = "futures" 58 | version = "0.3.16" 59 | source = "registry+https://github.com/rust-lang/crates.io-index" 60 | checksum = "1adc00f486adfc9ce99f77d717836f0c5aa84965eb0b4f051f4e83f7cab53f8b" 61 | dependencies = [ 62 | "futures-channel", 63 | "futures-core", 64 | "futures-executor", 65 | "futures-io", 66 | "futures-sink", 67 | "futures-task", 68 | "futures-util", 69 | ] 70 | 71 | [[package]] 72 | name = "futures-channel" 73 | version = "0.3.16" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | checksum = "74ed2411805f6e4e3d9bc904c95d5d423b89b3b25dc0250aa74729de20629ff9" 76 | dependencies = [ 77 | "futures-core", 78 | "futures-sink", 79 | ] 80 | 81 | [[package]] 82 | name = "futures-core" 83 | version = "0.3.16" 84 | source = "registry+https://github.com/rust-lang/crates.io-index" 85 | checksum = "af51b1b4a7fdff033703db39de8802c673eb91855f2e0d47dcf3bf2c0ef01f99" 86 | 87 | [[package]] 88 | name = "futures-executor" 89 | version = "0.3.16" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "4d0d535a57b87e1ae31437b892713aee90cd2d7b0ee48727cd11fc72ef54761c" 92 | dependencies = [ 93 | "futures-core", 94 | "futures-task", 95 | "futures-util", 96 | ] 97 | 98 | [[package]] 99 | name = "futures-io" 100 | version = "0.3.16" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "0b0e06c393068f3a6ef246c75cdca793d6a46347e75286933e5e75fd2fd11582" 103 | 104 | [[package]] 105 | name = "futures-macro" 106 | version = "0.3.16" 107 | source = "registry+https://github.com/rust-lang/crates.io-index" 108 | checksum = "c54913bae956fb8df7f4dc6fc90362aa72e69148e3f39041fbe8742d21e0ac57" 109 | dependencies = [ 110 | "autocfg", 111 | "proc-macro-hack", 112 | "proc-macro2", 113 | "quote", 114 | "syn", 115 | ] 116 | 117 | [[package]] 118 | name = "futures-sink" 119 | version = "0.3.16" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "c0f30aaa67363d119812743aa5f33c201a7a66329f97d1a887022971feea4b53" 122 | 123 | [[package]] 124 | name = "futures-task" 125 | version = "0.3.16" 126 | source = "registry+https://github.com/rust-lang/crates.io-index" 127 | checksum = "bbe54a98670017f3be909561f6ad13e810d9a51f3f061b902062ca3da80799f2" 128 | 129 | [[package]] 130 | name = "futures-util" 131 | version = "0.3.16" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "67eb846bfd58e44a8481a00049e82c43e0ccb5d61f8dc071057cb19249dd4d78" 134 | dependencies = [ 135 | "autocfg", 136 | "futures-channel", 137 | "futures-core", 138 | "futures-io", 139 | "futures-macro", 140 | "futures-sink", 141 | "futures-task", 142 | "memchr", 143 | "pin-project-lite", 144 | "pin-utils", 145 | "proc-macro-hack", 146 | "proc-macro-nested", 147 | "slab", 148 | ] 149 | 150 | [[package]] 151 | name = "hermit-abi" 152 | version = "0.1.19" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" 155 | dependencies = [ 156 | "libc", 157 | ] 158 | 159 | [[package]] 160 | name = "http" 161 | version = "0.2.4" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11" 164 | dependencies = [ 165 | "bytes", 166 | "fnv", 167 | "itoa", 168 | ] 169 | 170 | [[package]] 171 | name = "http-body" 172 | version = "0.4.2" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" 175 | dependencies = [ 176 | "bytes", 177 | "http", 178 | "pin-project-lite", 179 | ] 180 | 181 | [[package]] 182 | name = "httparse" 183 | version = "1.4.1" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" 186 | 187 | [[package]] 188 | name = "httpdate" 189 | version = "1.0.1" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440" 192 | 193 | [[package]] 194 | name = "hyper" 195 | version = "0.14.11" 196 | source = "registry+https://github.com/rust-lang/crates.io-index" 197 | checksum = "0b61cf2d1aebcf6e6352c97b81dc2244ca29194be1b276f5d8ad5c6330fffb11" 198 | dependencies = [ 199 | "bytes", 200 | "futures-channel", 201 | "futures-core", 202 | "futures-util", 203 | "http", 204 | "http-body", 205 | "httparse", 206 | "httpdate", 207 | "itoa", 208 | "pin-project-lite", 209 | "socket2", 210 | "tokio", 211 | "tower-service", 212 | "tracing", 213 | "want", 214 | ] 215 | 216 | [[package]] 217 | name = "itertools" 218 | version = "0.10.1" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" 221 | dependencies = [ 222 | "either", 223 | ] 224 | 225 | [[package]] 226 | name = "itoa" 227 | version = "0.4.7" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 230 | 231 | [[package]] 232 | name = "lambda_runtime" 233 | version = "0.3.0" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | checksum = "f9b08856997d11ca8122121b26b17a27ef1dce689d71ccd754e051f2417aebdd" 236 | dependencies = [ 237 | "async-stream", 238 | "bytes", 239 | "futures", 240 | "http", 241 | "hyper", 242 | "serde", 243 | "serde_json", 244 | "tokio", 245 | "tokio-stream", 246 | "tower-service", 247 | "tracing", 248 | "tracing-error", 249 | ] 250 | 251 | [[package]] 252 | name = "lamda-deno" 253 | version = "0.1.0" 254 | dependencies = [ 255 | "itertools", 256 | "lambda_runtime", 257 | "num", 258 | "serde_json", 259 | "tokio", 260 | ] 261 | 262 | [[package]] 263 | name = "lazy_static" 264 | version = "1.4.0" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 267 | 268 | [[package]] 269 | name = "libc" 270 | version = "0.2.98" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" 273 | 274 | [[package]] 275 | name = "log" 276 | version = "0.4.14" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 279 | dependencies = [ 280 | "cfg-if", 281 | ] 282 | 283 | [[package]] 284 | name = "memchr" 285 | version = "2.4.0" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" 288 | 289 | [[package]] 290 | name = "mio" 291 | version = "0.7.13" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "8c2bdb6314ec10835cd3293dd268473a835c02b7b352e788be788b3c6ca6bb16" 294 | dependencies = [ 295 | "libc", 296 | "log", 297 | "miow", 298 | "ntapi", 299 | "winapi", 300 | ] 301 | 302 | [[package]] 303 | name = "miow" 304 | version = "0.3.7" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" 307 | dependencies = [ 308 | "winapi", 309 | ] 310 | 311 | [[package]] 312 | name = "ntapi" 313 | version = "0.3.6" 314 | source = "registry+https://github.com/rust-lang/crates.io-index" 315 | checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" 316 | dependencies = [ 317 | "winapi", 318 | ] 319 | 320 | [[package]] 321 | name = "num" 322 | version = "0.4.0" 323 | source = "registry+https://github.com/rust-lang/crates.io-index" 324 | checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" 325 | dependencies = [ 326 | "num-bigint", 327 | "num-complex", 328 | "num-integer", 329 | "num-iter", 330 | "num-rational", 331 | "num-traits", 332 | ] 333 | 334 | [[package]] 335 | name = "num-bigint" 336 | version = "0.4.0" 337 | source = "registry+https://github.com/rust-lang/crates.io-index" 338 | checksum = "4e0d047c1062aa51e256408c560894e5251f08925980e53cf1aa5bd00eec6512" 339 | dependencies = [ 340 | "autocfg", 341 | "num-integer", 342 | "num-traits", 343 | ] 344 | 345 | [[package]] 346 | name = "num-complex" 347 | version = "0.4.0" 348 | source = "registry+https://github.com/rust-lang/crates.io-index" 349 | checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085" 350 | dependencies = [ 351 | "num-traits", 352 | ] 353 | 354 | [[package]] 355 | name = "num-integer" 356 | version = "0.1.44" 357 | source = "registry+https://github.com/rust-lang/crates.io-index" 358 | checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" 359 | dependencies = [ 360 | "autocfg", 361 | "num-traits", 362 | ] 363 | 364 | [[package]] 365 | name = "num-iter" 366 | version = "0.1.42" 367 | source = "registry+https://github.com/rust-lang/crates.io-index" 368 | checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" 369 | dependencies = [ 370 | "autocfg", 371 | "num-integer", 372 | "num-traits", 373 | ] 374 | 375 | [[package]] 376 | name = "num-rational" 377 | version = "0.4.0" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" 380 | dependencies = [ 381 | "autocfg", 382 | "num-bigint", 383 | "num-integer", 384 | "num-traits", 385 | ] 386 | 387 | [[package]] 388 | name = "num-traits" 389 | version = "0.2.14" 390 | source = "registry+https://github.com/rust-lang/crates.io-index" 391 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 392 | dependencies = [ 393 | "autocfg", 394 | ] 395 | 396 | [[package]] 397 | name = "num_cpus" 398 | version = "1.13.0" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" 401 | dependencies = [ 402 | "hermit-abi", 403 | "libc", 404 | ] 405 | 406 | [[package]] 407 | name = "once_cell" 408 | version = "1.8.0" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" 411 | 412 | [[package]] 413 | name = "pin-project-lite" 414 | version = "0.2.7" 415 | source = "registry+https://github.com/rust-lang/crates.io-index" 416 | checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" 417 | 418 | [[package]] 419 | name = "pin-utils" 420 | version = "0.1.0" 421 | source = "registry+https://github.com/rust-lang/crates.io-index" 422 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 423 | 424 | [[package]] 425 | name = "proc-macro-hack" 426 | version = "0.5.19" 427 | source = "registry+https://github.com/rust-lang/crates.io-index" 428 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" 429 | 430 | [[package]] 431 | name = "proc-macro-nested" 432 | version = "0.1.7" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" 435 | 436 | [[package]] 437 | name = "proc-macro2" 438 | version = "1.0.28" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" 441 | dependencies = [ 442 | "unicode-xid", 443 | ] 444 | 445 | [[package]] 446 | name = "quote" 447 | version = "1.0.9" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" 450 | dependencies = [ 451 | "proc-macro2", 452 | ] 453 | 454 | [[package]] 455 | name = "ryu" 456 | version = "1.0.5" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 459 | 460 | [[package]] 461 | name = "serde" 462 | version = "1.0.126" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "ec7505abeacaec74ae4778d9d9328fe5a5d04253220a85c4ee022239fc996d03" 465 | dependencies = [ 466 | "serde_derive", 467 | ] 468 | 469 | [[package]] 470 | name = "serde_derive" 471 | version = "1.0.126" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "963a7dbc9895aeac7ac90e74f34a5d5261828f79df35cbed41e10189d3804d43" 474 | dependencies = [ 475 | "proc-macro2", 476 | "quote", 477 | "syn", 478 | ] 479 | 480 | [[package]] 481 | name = "serde_json" 482 | version = "1.0.64" 483 | source = "registry+https://github.com/rust-lang/crates.io-index" 484 | checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" 485 | dependencies = [ 486 | "itoa", 487 | "ryu", 488 | "serde", 489 | ] 490 | 491 | [[package]] 492 | name = "sharded-slab" 493 | version = "0.1.1" 494 | source = "registry+https://github.com/rust-lang/crates.io-index" 495 | checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" 496 | dependencies = [ 497 | "lazy_static", 498 | ] 499 | 500 | [[package]] 501 | name = "slab" 502 | version = "0.4.3" 503 | source = "registry+https://github.com/rust-lang/crates.io-index" 504 | checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527" 505 | 506 | [[package]] 507 | name = "socket2" 508 | version = "0.4.0" 509 | source = "registry+https://github.com/rust-lang/crates.io-index" 510 | checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" 511 | dependencies = [ 512 | "libc", 513 | "winapi", 514 | ] 515 | 516 | [[package]] 517 | name = "syn" 518 | version = "1.0.74" 519 | source = "registry+https://github.com/rust-lang/crates.io-index" 520 | checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" 521 | dependencies = [ 522 | "proc-macro2", 523 | "quote", 524 | "unicode-xid", 525 | ] 526 | 527 | [[package]] 528 | name = "thread_local" 529 | version = "1.1.3" 530 | source = "registry+https://github.com/rust-lang/crates.io-index" 531 | checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" 532 | dependencies = [ 533 | "once_cell", 534 | ] 535 | 536 | [[package]] 537 | name = "tokio" 538 | version = "1.9.0" 539 | source = "registry+https://github.com/rust-lang/crates.io-index" 540 | checksum = "4b7b349f11a7047e6d1276853e612d152f5e8a352c61917887cc2169e2366b4c" 541 | dependencies = [ 542 | "autocfg", 543 | "bytes", 544 | "libc", 545 | "memchr", 546 | "mio", 547 | "num_cpus", 548 | "pin-project-lite", 549 | "tokio-macros", 550 | "winapi", 551 | ] 552 | 553 | [[package]] 554 | name = "tokio-macros" 555 | version = "1.3.0" 556 | source = "registry+https://github.com/rust-lang/crates.io-index" 557 | checksum = "54473be61f4ebe4efd09cec9bd5d16fa51d70ea0192213d754d2d500457db110" 558 | dependencies = [ 559 | "proc-macro2", 560 | "quote", 561 | "syn", 562 | ] 563 | 564 | [[package]] 565 | name = "tokio-stream" 566 | version = "0.1.7" 567 | source = "registry+https://github.com/rust-lang/crates.io-index" 568 | checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" 569 | dependencies = [ 570 | "futures-core", 571 | "pin-project-lite", 572 | "tokio", 573 | ] 574 | 575 | [[package]] 576 | name = "tower-service" 577 | version = "0.3.1" 578 | source = "registry+https://github.com/rust-lang/crates.io-index" 579 | checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" 580 | 581 | [[package]] 582 | name = "tracing" 583 | version = "0.1.26" 584 | source = "registry+https://github.com/rust-lang/crates.io-index" 585 | checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" 586 | dependencies = [ 587 | "cfg-if", 588 | "log", 589 | "pin-project-lite", 590 | "tracing-attributes", 591 | "tracing-core", 592 | ] 593 | 594 | [[package]] 595 | name = "tracing-attributes" 596 | version = "0.1.15" 597 | source = "registry+https://github.com/rust-lang/crates.io-index" 598 | checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" 599 | dependencies = [ 600 | "proc-macro2", 601 | "quote", 602 | "syn", 603 | ] 604 | 605 | [[package]] 606 | name = "tracing-core" 607 | version = "0.1.18" 608 | source = "registry+https://github.com/rust-lang/crates.io-index" 609 | checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" 610 | dependencies = [ 611 | "lazy_static", 612 | ] 613 | 614 | [[package]] 615 | name = "tracing-error" 616 | version = "0.1.2" 617 | source = "registry+https://github.com/rust-lang/crates.io-index" 618 | checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" 619 | dependencies = [ 620 | "tracing", 621 | "tracing-subscriber", 622 | ] 623 | 624 | [[package]] 625 | name = "tracing-subscriber" 626 | version = "0.2.19" 627 | source = "registry+https://github.com/rust-lang/crates.io-index" 628 | checksum = "ab69019741fca4d98be3c62d2b75254528b5432233fd8a4d2739fec20278de48" 629 | dependencies = [ 630 | "sharded-slab", 631 | "thread_local", 632 | "tracing-core", 633 | ] 634 | 635 | [[package]] 636 | name = "try-lock" 637 | version = "0.2.3" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" 640 | 641 | [[package]] 642 | name = "unicode-xid" 643 | version = "0.2.2" 644 | source = "registry+https://github.com/rust-lang/crates.io-index" 645 | checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" 646 | 647 | [[package]] 648 | name = "want" 649 | version = "0.3.0" 650 | source = "registry+https://github.com/rust-lang/crates.io-index" 651 | checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" 652 | dependencies = [ 653 | "log", 654 | "try-lock", 655 | ] 656 | 657 | [[package]] 658 | name = "winapi" 659 | version = "0.3.9" 660 | source = "registry+https://github.com/rust-lang/crates.io-index" 661 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 662 | dependencies = [ 663 | "winapi-i686-pc-windows-gnu", 664 | "winapi-x86_64-pc-windows-gnu", 665 | ] 666 | 667 | [[package]] 668 | name = "winapi-i686-pc-windows-gnu" 669 | version = "0.4.0" 670 | source = "registry+https://github.com/rust-lang/crates.io-index" 671 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 672 | 673 | [[package]] 674 | name = "winapi-x86_64-pc-windows-gnu" 675 | version = "0.4.0" 676 | source = "registry+https://github.com/rust-lang/crates.io-index" 677 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 678 | -------------------------------------------------------------------------------- /rust-lambda/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lamda-deno" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | lambda_runtime = "0.3.0" 10 | tokio = "1.9.0" 11 | serde_json = "1.0.64" 12 | itertools = "0.10.1" 13 | num = "0.4.0" 14 | 15 | [[bin]] 16 | name = "bootstrap" 17 | path = "src/main.rs" 18 | 19 | [profile.release] 20 | opt-level = 3 21 | lto = true 22 | -------------------------------------------------------------------------------- /rust-lambda/src/main.rs: -------------------------------------------------------------------------------- 1 | use lambda_runtime::{Context, handler_fn}; 2 | use serde_json::{Value, json}; 3 | use itertools::Itertools; 4 | use num::{FromPrimitive, Integer}; 5 | use std::{collections::{HashMap, HashSet}}; 6 | 7 | 8 | #[derive(Debug, PartialEq, Eq)] 9 | pub struct Palindrome { 10 | factors: HashSet<(u64, u64)>, 11 | value: u64, 12 | } 13 | 14 | impl Palindrome { 15 | pub fn new(a: u64, b: u64) -> Palindrome { 16 | let mut set: HashSet<(u64, u64)> = HashSet::new(); 17 | set.insert((a, b)); 18 | Self { 19 | value: a * b, 20 | factors: set, 21 | } 22 | } 23 | 24 | pub fn value(&self) -> u64 { 25 | self.value 26 | } 27 | 28 | pub fn insert(&mut self, a: u64, b: u64) { 29 | self.factors.insert((a, b)); 30 | } 31 | } 32 | 33 | fn is_palindrome(a: u64, b: u64) -> bool { 34 | let prod = a * b; 35 | prod == reverse(prod) 36 | } 37 | 38 | /// Reverses an unsigned integer number (e.g. 123 -> 321) 39 | fn reverse(a: T) -> T { 40 | let radix = FromPrimitive::from_usize(10).unwrap(); 41 | let mut n = a; 42 | let mut reversed = FromPrimitive::from_usize(0).unwrap(); 43 | 44 | while !n.is_zero() { 45 | reversed = reversed * radix + n % radix; 46 | n = n / radix; 47 | } 48 | 49 | reversed 50 | } 51 | 52 | fn check_palindrom(map: &mut HashMap, a: u64, b: u64) { 53 | if is_palindrome(a, b) { 54 | let prod = a * b; 55 | map.entry(prod) 56 | .or_insert_with(|| Palindrome::new(a, b)) 57 | .insert(a, b); 58 | } 59 | } 60 | 61 | pub fn palindrome_products(min: u64, max: u64) -> Option<(Palindrome, Palindrome)> { 62 | let mut map: HashMap = HashMap::new(); 63 | 64 | for (a, b) in (min..=max).tuple_combinations() { 65 | check_palindrom(&mut map, a, b); 66 | } 67 | for c in min..=max { 68 | check_palindrom(&mut map, c, c); 69 | } 70 | 71 | let prod_min_max = map.keys().minmax().into_option(); 72 | 73 | if let Some((i, j)) = prod_min_max { 74 | let (i, j) = (i.to_owned(), j.to_owned()); 75 | Some((map.remove(&i).unwrap(), map.remove(&j).unwrap())) 76 | } else { 77 | None 78 | } 79 | } 80 | 81 | 82 | #[tokio::main] 83 | async fn main() -> Result<(), lambda_runtime::Error>{ 84 | let func = handler_fn(handler); 85 | lambda_runtime::run(func).await?; 86 | Ok(()) 87 | } 88 | 89 | async fn handler(event: Value, _: Context) -> Result { 90 | let (min, max) = match (event["min"].as_u64(), event["max"].as_u64()) { 91 | (Some(min), Some(max)) => (min, max), 92 | _ => (0, 0) 93 | }; 94 | match palindrome_products(min, max) { 95 | Some((pal_1, pal_2)) => Ok(json!({ "palindromes": { "one": pal_1.value, "two": pal_2.value } })), 96 | None => Ok(json!({ "message": "none found" })) 97 | } 98 | } 99 | --------------------------------------------------------------------------------