Skip to content

Instantly share code, notes, and snippets.

View gftea's full-sized avatar
👻

gftea gftea

👻
View GitHub Profile
use std::error::Error;
type Result<T> = std::result::Result<T, Box<dyn Error>>;
pub trait Parser: Sized {
type Output;
fn parse(self) -> Result<Self::Output>;
}
impl<F, T> Parser for F
where

Benchmarking client_amqprs::amqprs_basic_pub: Complete (Analysis Disabled)

strace -c target/release/deps/basic_pub-3b2b0ff1b8c7dee5 --bench --profile-time 10 amqprs

% time seconds usecs/call calls errors syscall
69.84 0.803361 57 13972 603 futex
29.62 0.340743 46 7255 write
0.18 0.002044 51 40 clone
0.08 0.000968 30 32 sendto
0.06 0.000646 26 24 epoll_ctl
trait Hello {
fn say_hello() -> Self;
}
impl Hello for i32 {
fn say_hello() -> i32 {
println!("hello i32");
0i32
}
}
impl Hello for usize {
#![allow(unused)]
use std::rc::Rc;
use std::cell::RefCell;
#[derive(Debug, PartialEq)]
struct Node;
fn main() {
{
// case 1, normal
#[derive(Debug)]
enum Say {
Hello(String), // == `fn Hello(s: String) -> Say`
Hej(String), // == `fn Hej(s: String) -> Say`
}
fn say(msg: String, f: fn (s: String) -> Say) {
println!("{:?}", f(msg));
}
use async_runtime::Runtime;
use async_runtime::net::AsyncTcpStream;
fn main() {
let rt = Runtime;
rt.run(async {
println!("top future start");
let mut stream = AsyncTcpStream::connect("127.0.0.1:8080");
let mut buf = vec![0;100];
let n = stream.read(&mut buf).await;
use std::{
future::Future,
mem::forget,
sync::Arc,
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
thread,
time::Duration,
};
use std::{
future::Future,
io::{self, Read, Write},
net::{Shutdown, TcpStream},
pin::Pin,
task::{Context, Poll},
};
/// just to wrap a TcpStream in order to implement different interfaces
/// User can use this type like below
/// ```
use futures::{
task::{waker_ref, ArcWake}, // to create `context` from type implements ArcWake trait
FutureExt, // to use `Future::boxed` method
};
use std::{
future::Future,
sync::Arc,
task::{Context, Poll},
};
% Input signal: s(t) = 0.5 * cos(2*pi*800*t) - 0.5 * cos(2*pi*1200*t);
% mixer wave: c(t) = cos(2*pi*5000*t)
f1 = 800
f2 = 1200
fc = 5000
% FFT size
N = 1024