View main.rs
This file contains 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
// This is a technique to emulate lifetime GATs (generic associated types) on stable rust starting | |
// with rustc 1.33. | |
// | |
// I haven't seen this exact technique before, but I would be surprised if no one else came up with | |
// it. I think this avoids most downsides of other lifetime GAT workarounds I've seen. | |
// | |
// In particular, neither implementing nor using traits with emulated lifetime GATs requires adding | |
// any helper items. Only defining the trait requires a single helper trait (+ a single helper impl | |
// for the 2nd variant) per GAT. This also makes the technique viable without any boilerplate | |
// reducing macros. |
View openocd-unmatched.cfg
This file contains 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
adapter speed 10000 | |
adapter driver ftdi | |
ftdi_device_desc "Dual RS232-HS" | |
ftdi_vid_pid 0x0403 0x6010 | |
ftdi_layout_init 0x0008 0x001b | |
ftdi_layout_signal nSRST -oe 0x0020 -data 0x0020 | |
set _CHIPNAME riscv | |
transport select jtag |
View dedup.rs
This file contains 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
fn iterative_save<W: Write>(&self, mut wtr: W) -> Result<&Self> { | |
for row in self { | |
for (i, col) in row.iter().enumerate() { | |
match i { | |
0 => wtr.write_all(col.as_bytes())?, | |
_ => { | |
wtr.write_all(b",")?; | |
wtr.write_all(col.as_bytes())? | |
} | |
} |
View cg_bowling_game.rs
This file contains 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
fn main() { | |
let game = "X 7/ 9- X F8 ⑧/ F6 X X X8/" | |
.chars() | |
.filter(|c| !c.is_whitespace()) | |
.fold(Vec::new(), |mut rolls, roll| { | |
match roll { | |
'X' => rolls.push(10_u8), | |
'/' => rolls.push(10 - rolls.last().expect("invalid game score")), | |
c if c >= '0' && c <= '9' => rolls.push((u32::from(c) - 0x30) as u8), | |
c if c >= '⑤' && c <= '⑧' => rolls.push((u32::from(c) - 0x245f) as u8), |
View AutoFacGettingStarted.rs
This file contains 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(existential_type)] | |
use chrono::Local; | |
use std::io::{self, Write}; | |
type Result<T> = std::result::Result<T, failure::Error>; | |
trait IOutput { | |
fn write(&self, content: &String) -> Result<()>; | |
} | |
struct ConsoleOutput {} |
View AutoFacGettingStarted.cs
This file contains 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
using System; | |
using Autofac; | |
namespace DemoApp | |
{ | |
// This interface helps decouple the concept of | |
// "writing output" from the Console class. We | |
// don't really "care" how the Write operation | |
// happens, just that we can write. | |
public interface IOutput |
View di.rs
This file contains 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(existential_type)] | |
type Result<T> = std::result::Result<T, failure::Error>; | |
trait MyTrait { | |
fn greet(&self) -> String; | |
} | |
struct MyType {} |
View .bashrc
This file contains 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
# ~/.bashrc: executed by bash(1) for non-login shells. | |
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) | |
# for examples | |
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac |
View default_clippy_lints.rs
This file contains 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
#![forbid(overflowing_literals,)] | |
#![deny(unsafe_code)] // Do not remove! Change to `allow` to explicitly opt-in to using `unsafe` (facilitates auditing) | |
// vvv Safety-critical application lints (pedantic: use for safety-critical applications only) vvv | |
#![deny(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_precision_loss, | |
clippy::cast_sign_loss, clippy::float_cmp_const, clippy::indexing_slicing, clippy::integer_arithmetic, | |
clippy::maybe_infinite_iter, clippy::option_unwrap_used, clippy::result_unwrap_used,)] | |
// ^^^ End of safety-critical lint section ^^^ | |
#![warn(clippy::clone_on_ref_ptr, clippy::decimal_literal_representation, clippy::default_trait_access, | |
clippy::doc_markdown, clippy::else_if_without_else, clippy::empty_enum, clippy::enum_glob_use, | |
clippy::expl_impl_clone_on_copy, clippy::fallible_impl_from, clippy::filter_map, clippy::if_not_else, |
View associated_consts_cannot_be_reference_in_patterns
This file contains 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
enum State { | |
On, | |
Off, | |
} | |
trait Foo { | |
const STATE: State; | |
} | |
struct A; |
NewerOlder