Skip to content

Instantly share code, notes, and snippets.

View octave99's full-sized avatar

octave99 octave99

View GitHub Profile
@octave99
octave99 / generics_over_generics.rs
Created July 23, 2019 10:46
Store generic with trait bound
use std::path::Path;
use std::io::Read;
pub struct AnimalFile<P> {
reader: P,
}
impl<P> AnimalFile<P>
where
P: NewBufRead<std::fs::File>,
use std::{
borrow::{Borrow, Cow},
fmt::Debug,
};
fn say<'a, C, B>(first_name: C, last_name: &B)
where
C: Into<Cow<'a, str>> + Debug + ?Sized,
B: Borrow<str> + Debug + ?Sized,
{
use std::cell::RefCell;
use std::rc::Rc;
pub struct MyStruct {
name: String,
}
fn error_fn() {
let mut ms = MyStruct {
name: "Before".to_owned(),
#[derive(Clone, Copy)]
pub struct MyStruct<'a> {
name: &'a str,
}
impl<'a> MyStruct<'a> {
fn new() -> Self {
MyStruct { name: "Before" }
}
pub struct MyStruct<'a> {
name: &'a str,
}
impl<'a> MyStruct<'a> {
fn new() -> Self {
MyStruct { name: "Before" }
}
fn read(&self) {
pub struct MyStruct<T> {
pub value: T,
}
impl MyStruct<u32> {
fn new(value: u32) -> Self {
MyStruct { value }
}
}
use std::fmt::{Debug, Formatter};
pub struct MyStruct<T> {
pub value: T,
}
impl<T> MyStruct<T> {
fn new(v: T) -> Self {
MyStruct { value: v }
}
use futures::future::{Future, ok, select_ok}; // 0.1.26
use tokio; // 0.1.18
use tokio_timer::sleep; // 0.2.10
use std::time::Duration;
fn i() -> impl Future<Item=(), Error=()> {
print!("Immediate\n");
ok(())
}
fn d() -> impl Future<Item=(), Error=()> {
use futures::sync::oneshot::{channel, Receiver, Sender};
use futures::{
future::{lazy, ok, Future},
Async, Poll,
};
use tokio;
use tokio_timer::sleep;
use std::time::Duration;
use futures::{
future::{lazy, ok, Future},
Async, Poll,
};
use std::time::Duration;
use tokio;
use tokio_timer::sleep;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;