This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Index; | |
struct Foo<T> { | |
val: T, | |
} | |
impl<T> Index<usize> for (&Foo<T>, &str) { | |
type Output = T; | |
fn index(&self, _: usize) -> &T { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::convert::Infallible; | |
use std::net::SocketAddr; | |
use hyper::{Body, Request, Response, Server, StatusCode}; | |
use hyper::service::{make_service_fn, service_fn}; | |
#[tokio::main] | |
async fn main() { | |
let addr = SocketAddr::from(([127, 0, 0, 1], 3030)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::{self, BufRead}; | |
struct Migration<'a> { | |
pub namespace: &'a str, | |
} | |
impl<'a> Migration<'a> { | |
pub fn len(&self) -> usize { | |
self.namespace.chars().count() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate futures; | |
extern crate reqwest; | |
extern crate scraper; | |
use futures::{future, Future}; | |
use scraper::{Html, Selector}; | |
use std::time::Instant; | |
async fn get_doc(url: &str) -> Result<String, Box<dyn std::error::Error>> { | |
let doc = reqwest::get(url).await?.text().await?; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate futures; | |
extern crate reqwest; | |
extern crate scraper; | |
use futures::{future, Future}; | |
use scraper::{Html, Selector}; | |
use std::time::Instant; | |
async fn get_doc(url: &str) -> Result<String, Box<dyn std::error::Error>> { | |
let doc = reqwest::get(url).await?.text().await?; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::mem::ManuallyDrop; | |
use std::convert::TryInto; | |
fn main() { | |
let mut a = String::with_capacity(50); | |
a.push_str("öäasdkflieojf"); | |
let (b,c) = unsafe{split(a, 4)}; | |
println!("{} and {}, capacities: {}, {}", b, c, b.capacity(), c.capacity()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Int32(i32); | |
struct Int64(i64); | |
pub trait Num { | |
fn new() -> Self; | |
} | |
impl Num for Int32 { | |
fn new() -> Self { Int32(0) } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cmp::max; | |
use rayon::prelude::*; | |
fn max_k(n: u64) -> u64 { | |
let p = n as f64; | |
return ((((8.0f64*p)+1.0f64).sqrt()-1.0f64)/2.0f64) as u64; | |
} | |
fn f(n: u64, k: &u64) -> u64 { | |
let total = (k*(k+1))/2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Int32(i32); | |
struct Int64(i64); | |
pub trait Num { | |
fn new() -> Self; | |
} | |
impl Num for Int32 { | |
fn new() -> Self { Int32(0) } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused)] | |
fn main() { | |
/// Adds one to the number given. | |
/// | |
/// # Examples | |
/// | |
/// ``` | |
/// let five = 5; | |
/// | |
/// assert_eq!(6, my_crate::add_one(5)); |