Why is it that there is anOption.expect(M)
, but noResult.expect(M)
?
I opened a pull request [pr] which put this in, and it turns out the reason there is no expect
function is because you are intended to use composition:
type | |
RPizza = ref Pizza | |
Pizza = object | |
Backref: RPizza | |
proc NoPizza(self: RPizza) = | |
debugEcho "Pizza eaten by ghosts." | |
proc main() = |
import | |
rectangle | |
type | |
MaxRectPacker* [T] = object | |
initialWidth, initialHeight: T | |
freeGeometry: seq[Rectangle[T]] | |
proc TryGet* [T](self: var MaxRectPacker[T]; |
import unittest | |
proc doThings(spuds: var int): int = | |
spuds = 24 | |
return 99 | |
suite "broken": | |
test "count the spuds": | |
var spuds = 0 | |
check doThings(spuds) == 99 |
#[crate_id = "mu1"]; | |
#[crate_type = "bin"]; | |
use std::cast::transmute; | |
use std::cell::RefCell; | |
use std::libc::size_t; | |
use std::rc::{Rc, Weak}; | |
static ErrAlreadyParented: &'static str = "Morph already has a parent."; |
pub trait ApplicationDelegate { | |
fn application_did_quit(&mut self, _timestamp: u32) {} | |
} | |
pub trait MouseDelegate { | |
fn mouse_did_move(&mut self, _info: &MouseMotionEventInfo) {} | |
fn mouse_did_click(&mut self, _info: &MouseButtonEventInfo) {} | |
fn mouse_did_scroll(&mut self, _info: &MouseWheelEventInfo) {} | |
} |
fn main() { | |
let mut sentry = sdl::init(sdl::init::Video).unwrap(); | |
let win = sentry.new_window("Foof wob", 32, 32, 800, 600, 0).unwrap(); | |
let mut x = win.borrow_mut(); | |
/* does this work for putting the trait types in? */ | |
sentry.set_application_delegate(&Foof as &sdl::ApplicationDelegate); | |
x.get().set_mouse_delegate(&Foof as &sdl::MouseDelegate); |
#[inline] | |
unsafe fn with_window_event_db(_in: &CommonEventInfo, block: |&mut DelegateBoard|) { | |
let event : &MouseMotionEventInfo = cast::transmute(_in); | |
EventPump::with_window_db(event.window_id(), block) | |
} | |
unsafe fn with_window_db(id: u32, block: |&mut DelegateBoard|) { | |
let win = ffi::SDL_GetWindowFromID(id); | |
if win.is_not_null() { | |
let dbp = ffi::SDL_GetWindowData(win, bytes!("rust_cb", 0).as_ptr() as *i8); |
extern mod sdl; | |
use std::rc::Rc; | |
struct Foof; | |
impl sdl::MouseDelegate for Foof { | |
fn mouse_did_move(_info: &sdl::MouseMotionEventInfo) { | |
println!("Mouse position: {}x{}", _info.x(), _info.y()) |
Why is it that there is anOption.expect(M)
, but noResult.expect(M)
?
I opened a pull request [pr] which put this in, and it turns out the reason there is no expect
function is because you are intended to use composition:
This document is a work in progress, and is primarily concerned with getting Rust code able to talk with C code. What we cover here is writing 'bindings', we will cover 'wrapping' up the bindings and providing an elegant interface in the next document.