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 core::pin::Pin; | |
use core::marker::PhantomPinned; | |
#[derive(Debug)] | |
struct Unm(i32, PhantomPinned); // !Unpin | |
//struct Unm(i32); // Unpin | |
fn foo() -> Pin<Box<Unm>> { | |
// PhantomPinned is !Unpin so Pin does not implement get_mut (disallowing mem::swap/replece and then move) nor into_inner (move out Unm of Box) | |
Box::pin(Unm(1, PhantomPinned)) |
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
#![feature(type_alias_impl_trait)] | |
use std::io::Read; | |
use std::io::Cursor; | |
struct B(String); | |
struct RefPairA<'b>(&'b B, String); | |
trait GetPair { | |
fn pair(&self) -> (&str, &str); |
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
#!/usr/bin/env denim | |
/* Cargo.toml | |
[package] | |
name = "smuggle" | |
version = "0.1.0" | |
authors = ["Anonymous"] | |
edition = "2018" | |
[dependencies] |
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::any::{Any, TypeId}; | |
use std::fmt::Debug; | |
pub trait Resource: Any + Debug { | |
// this returns correct function for the Self to work on Box so that it can be casted and unboxed | |
fn combine_fn(&self) -> fn(left: Box<dyn Resource>, right: Box<dyn Resource>) -> Box<dyn Resource>; | |
} | |
#[derive(Debug)] | |
struct File(u32); |
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::sync::Mutex; | |
use std::sync::RwLock; | |
use std::sync::Arc; | |
use std::collections::HashMap; | |
use lazy_static::lazy_static; | |
lazy_static! { | |
static ref CACHE: Mutex<HashMap<&'static str, Arc<RwLock<Option<u32>>>>> = Mutex::new(HashMap::new()); | |
} |
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::marker::PhantomData; | |
struct Connection(u32); | |
impl Connection { | |
fn statement(&self) -> Statement { | |
Statement(Raii(self.0), PhantomData) | |
} | |
} |
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
#!/usr/bin/env denim | |
// | |
// Example script description | |
// | |
/* Cargo.toml | |
[package] | |
name = "mullvard" | |
version = "0.1.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
#![feature(const_generics)] | |
#![feature(const_generic_impls_guard)] | |
trait CsvRecord<const COLS: usize> { | |
fn columns() -> [&'static str; COLS]; | |
fn values(&self) -> [String; COLS]; | |
} | |
struct Foo { | |
id: u32, |
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
#!/usr/bin/env denim | |
/* Cargo.toml | |
[package] | |
name = "tracer" | |
version = "0.1.0" | |
authors = ["Anonymous"] | |
edition = "2018" | |
[dependencies] |
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
// https://stackoverflow.com/questions/50519147/double-mutable-borrow-error-in-a-loop-happens-even-with-nll-on | |
// https://github.com/rust-lang/rust/issues/54663 | |
// This will complie with polonius: rustc +nightly -Zpolonius --edition=2018 /tmp/p.rs | |
struct Foo(u8); | |
impl Foo { | |
fn even<'i>(&'i mut self) -> &'i u8 { | |
loop { | |
match self.next() { | |
Some(even) => return even, |
NewerOlder