Skip to content

Instantly share code, notes, and snippets.

View aturon's full-sized avatar

Aaron Turon aturon

View GitHub Profile
trait AsRef<T: ?Sized> {
fn convert_as_ref(&self) -> &T;
}
trait Into<T> {
fn convert_into(self) -> T;
}
trait From<T> {
fn from(T) -> Self;
// As lifts over Deref
impl<D: ?Sized + Deref, U: ?Sized> AsRef<U> for D where D::Target: AsRef<U> {
fn as_ref(&self) -> &U {
self.deref().as_ref()
}
}
trait Rand<Distribution> {
type Stream: RandStream<T>;
fn rand(dist: Distribution) -> Stream;
}
trait RandStream<T> {
fn next<R: Rng>(&self, rng: &mut R) -> T;
}
impl Rand<Range<u32, u32>> for u32 {
trait Rand<Rng, Distribution> {
type Iter: Iterator<Item = Self>;
fn rand(rng: Rng, dist: Distribution) -> Iter;
}
fn nonparametric<T: 'static>(t: T) {
let b: Box<Any> = box t;
match b.downcast::<SomeConcreteType>() {
...
}
}
trait CoerceFrom<T> {
fn coerce_from(T) -> Self;
}
trait Coerce {
fn coerce<T>(self) -> T where T: CoerceFrom<Self>;
}
impl<T> Coerce for T {
fn coerce<U: CoerceFrom<T>>(self) -> U {
// Types: Path and path (later being unsized)
impl Deref<path> for Path { ... }
fn new<T: BytesContainer>(path: T) -> Path
fn dir(&self) -> &path
impl Path {
fn new<T: BytesContainer>(path: T) -> Path
fn nth(&mut self, mut n: uint) -> Option<A> {
for x in *self {
if n == 0 { return Some(x) }
n -= 1;
}
None
}
error: cannot borrow immutable local variable `self` as mutable
for x in *self {
This file has been truncated, but you can view the full file.
; ModuleID = 'test-addrinfo.0.rs'
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-gnu"
%str_slice = type { i8*, i64 }
%"struct.core::intrinsics::TypeId<[]>[#3]" = type { i64 }
%"struct.task::Ops<[]>" = type { %"struct.rustrt::mutex::NativeMutex<[]>[#9]", i8, { i64, i64 }, i64 }
%"struct.rustrt::mutex::NativeMutex<[]>[#9]" = type { %"struct.rustrt::mutex::StaticNativeMutex<[]>[#9]", i8 }
%"struct.rustrt::mutex::StaticNativeMutex<[]>[#9]" = type { %"struct.rustrt::mutex::imp::Mutex<[]>[#9]" }
%"struct.rustrt::mutex::imp::Mutex<[]>[#9]" = type { %"struct.core::atomic::AtomicUint<[]>[#3]", %"struct.core::atomic::AtomicUint<[]>[#3]" }
failures:
---- io::net::addrinfo::test::dns_smoke_test stdout ----
task 'io::net::addrinfo::test::dns_smoke_test' panicked at 'called `Result::unwrap()` on an `Err` value: OS Error 0: The operation completed successfully.
', C:\msys64\home\aturon\rust\src\libcore\result.rs:788