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
// Find XCB screen. | |
int default_screen_number = XDefaultScreen(display); | |
xcb_screen_t *screen = NULL; | |
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); | |
int index = 0; | |
do { | |
if (index == default_screen_number) { | |
screen = iter.data; | |
break; |
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(nonzero)] | |
extern crate core; | |
mod gl { | |
use core::nonzero::NonZero; | |
#[derive(Debug)] | |
pub struct Context { | |
texture_id_counter: u32, | |
active_texture_unit_index: TextureUnitIndex, |
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
#[no_mangle] | |
#[inline(never)] | |
pub fn on_change(x: u32) { | |
println!("x is now {}", x); | |
} | |
struct X(u32); | |
impl X { | |
fn change(&mut self, y: 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
trait Pi { | |
fn give_me_pi() -> f32; | |
} | |
struct PI(); | |
impl Pi for PI { | |
fn give_me_pi() -> f32 { | |
3.14 | |
} |
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(fn_must_use)] | |
#[cfg(test)] | |
mod tests { | |
use std::ops::{Sub, Add, Mul, Div}; | |
trait Unit { | |
type Value; | |
fn value(&self) -> Self::Value; |
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 gl; | |
extern crate cgmath; | |
use gl::types::*; | |
use cgmath::*; | |
macro_rules! def_accessor_trait { | |
(($Trait:ident, $method:ident), ($TraitMut:ident, $method_mut:ident), $Field:ty) => { | |
pub trait $Trait { | |
fn $method(&self) -> &$Field; |
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
// Consider the following calls: | |
// PrintAngle((Radians) 0.10, "radians"); | |
// PrintAngle((Degrees) 30, "degrees"); | |
// Obviously no conversion are required, but without the IAngularUnit | |
// interface, we would have to provide copies of this method for each | |
// Unit manually. | |
public static void PrintAngle<TAngularUnit>(TAngularUnit angle, string unit) where TAngularUnit : IAngularUnit { | |
switch (unit) { | |
case "radians": System.Console.WriteLine("{0:F2} rad", (float) angle.ToRadians); break; | |
case "degrees": System.Console.WriteLine("{0:F2} deg", (float) angle.ToDegrees); break; |
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
// Some constants, may get them from another place in production code. | |
internal abstract class Constants { | |
public const float RadiansPerCircle = 2.0f*(float) System.Math.PI; | |
public const float DegreesPerCircle = 360.0f; | |
public const float RadiansPerDegree = RadiansPerCircle/DegreesPerCircle; | |
public const float DegreesPerRadian = DegreesPerCircle/RadiansPerCircle; | |
} | |
public interface IAngularUnit { | |
float AsRadians { get; } |
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
#[derive(Clone,Copy,Debug)] | |
enum State { | |
A, | |
B, | |
Trap, | |
} | |
impl State { | |
fn is_accepting(self) -> bool { | |
use State::*; |
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
# http://editorconfig.org/ | |
root = true | |
[*] | |
charset = utf-8 | |
end_of_line = lf | |
indent_size = 2 | |
indent_style = space | |
insert_final_newline = true | |
max_line_length = 72 |
NewerOlder