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
use std::{io,mem,raw,cast}; | |
struct BlobContainingSlices<'a> { | |
data:~[u8], | |
subset1: &'a [u32], | |
subset2: &'a [u16], | |
} | |
fn slice_within_as<TO,FROM>(owner:&[FROM], start:uint, len_in_new_units:uint)->&[TO] { |
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(macro_rules)]; | |
use std::{cast}; | |
// emulating C++ classes using Traits as vtables, could the safety be improved? | |
pub trait Foo { | |
fn foo(&self,i:int); | |
} | |
pub struct CppClass<RawDataStruct,TraitInterface> { |
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(macro_rules)]; | |
#[allow(macro_rules)]; | |
use std::{io,mem,raw,cast}; | |
// emulating C++ classes using Traits as vtables, could the safety be improved? | |
pub trait Foo { | |
fn foo(&self,i:int); | |
} | |
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
struct A{ | |
x:int,y:int | |
} | |
struct B{ | |
p:int,q:int | |
} | |
struct C{ | |
a:A,b:B | |
} |
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(default_type_params)] | |
use std::iter::RandomAccessIterator; | |
trait ScatterInto<'a, T,INDEX=uint> { | |
fn scatter_into<SRC:Iterator<(INDEX,T)>> (&mut self, src:SRC); | |
fn scatter_by_indices<IDXS:Iterator<INDEX>, TS:Iterator<T>> (&mut self, indices:IDXS,values:TS) { self.scatter_into(indices.zip(values) ) } | |
} | |
trait ScatterIntoGrow<'a, T,INDEX=uint> { | |
/// Scatter values into a collection, and grow it if its not large enough |
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
struct Vec3<T>{x:T,y:T,z:T} | |
impl<'a, A,B> From<Vec3<B>> for Vec3<A> where A:From<B>+Copy,B:Copy { | |
fn from(b:Vec3<B>)->Self { | |
Vec3::<A>{ x: b.x.into(), y: b.y.into(), z: b.z.into() } | |
} | |
} | |
error[E0119]: conflicting implementations of trait `std::convert::From<r3d::vecmath::Vec3<_>>` for type `r3d::vecmath::Vec3<_>`: |
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
pub fn lerp_r1<'a,'b,'f,'d,'p,F,T,D,P>((a,b):(&'a T,&'b T), f:&'f F)->T where | |
&'b T:Sub<&'a T,Output=D>, | |
&'f F:Mul<&'d D,Output=P>, | |
&'a T:Add<&'p P, Output=T>, | |
D:'d, | |
P:'p | |
{ | |
a + &(f * &(b-a)) | |
} |
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
pub fn madd_r1<'a,'b,'c,'p,A,B,C,P>(a:&'a A,b:&'b B,c:&'c C)->A where | |
&'b B:Mul<&'c C,Output=P>, | |
&'a A:Add<&'p P,Output=A>, | |
P:'static, | |
{ | |
let p=b*c; | |
a + &p | |
} | |
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 compiles, but didn't need lifetime annotations. | |
// what does this do differently compared to the version using operators? | |
pub trait MulRef<B> { | |
type Output; | |
fn mul_ref(&self,&B)->Self::Output; | |
} | |
pub trait AddRef<B> { | |
type Output; | |
fn add_ref(&self,&B)->Self::Output; |
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
/// means of throwing ints into the typesys | |
pub struct TN7{} | |
/// means of throwing ints into the typesys | |
pub struct TN15{} | |
/// means of throwing ints into the typesys | |
pub struct TN16{} | |
/// means of throwing ints into the typesys | |
pub struct TN12{} | |
/// means of throwing ints into the typesys |