# ======== SERVER COMMS MODEL ========= #
# ↑↓ PLAYER SPECTATOR #
# 01 T version version #
# 02 R register register #
# 03 T welcome welcome #
# ------------- [...] --------------- #
# 04 T game game #
# 05 T round round #
# 06 R move move #
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
| fn round(mut game: Game<Box<Rng>>, | |
| players: MsgRoom<String>, | |
| spectator_tx: mpsc::Sender<Msg>, | |
| timeout: Milliseconds, | |
| timer: &tokio_timer::Timer) | |
| -> Box<Future<Item = (Game<Box<Rng>>, | |
| MsgRoom<String>, | |
| mpsc::Sender<Msg>, | |
| Milliseconds, |
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
| use std::time::Duration; | |
| use futures::{Future, Sink, Stream, Poll, Async}; | |
| use super::*; | |
| pub struct Receive<I, C> | |
| where I: Clone + Send + Debug + 'static, | |
| C: Sink + Stream + 'static, | |
| C::SinkError: Clone, | |
| C::Error: Clone | |
| { |
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
| # Install these Ruby Gems (packages): | |
| # `gem install colorize humanize` | |
| # Call in your shell profile (e.g., ~/.zshrc): | |
| # `ruby deadlines.rb` | |
| require 'colorize' | |
| require 'humanize' | |
| require 'date' | |
| needed = [[18000, "words"], [55, "pages"]] |
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
| fn main() { | |
| let mut xs = vec![Some(5), None, Some(3)]; | |
| // Sadly, this never prints. | |
| for x in xs { | |
| let n = x.unwrap_or(continue); | |
| println!("{}", n); | |
| } | |
| } |
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
| if let Some(&mut rx) = self.rx.as_mut() { | |
| if let Some(item) = match rx.poll() { | |
| Ok(Async::NotReady) => None, | |
| Ok(Async::Ready(item)) => Some(Ok(item)), | |
| Err(e) => Some(Err(CappedError::StreamError(e))) | |
| } { | |
| // Even if the cap is exceeded, buffer this final item. | |
| self.buffer.push_back(item); | |
| // If the updated queue exceeds the buffer size, drop the Stream. | |
| if self.buffer.len() > self.buffer_size { |
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
| use std::marker::PhantomData; | |
| use std::ptr; | |
| use std::mem; | |
| use std::ops::Add; | |
| /// This type is only every inhabited when S is nominally equivalent to T | |
| #[derive(Debug)] | |
| pub struct Is<S, T>(PhantomData<(*const S, *const T)>); | |
| // Construct a proof of the fact that a type is nominally equivalent |
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(box_syntax, box_patterns)] | |
| #![allow(dead_code)] | |
| use std::ops::{Deref, DerefMut}; | |
| use std::collections::VecDeque; | |
| use std::fmt::{Debug, Formatter, Error}; | |
| pub struct BoxTree<T>(Box<T>) where T: Tree; | |
| impl<T> BoxTree<T> |
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(PartialEq, Clone, Debug, Serialize, Deserialize)] | |
| #[serde(tag = "kind", content = "data", namecasing = "snake_case")] | |
| pub enum Msg { | |
| #[serde(namecasing = "SCREAMING_SNAKE_CASE")] | |
| Version { sirpent: String, protocol: String }, | |
| Register { | |
| desired_name: String, | |
| kind: ClientKind, | |
| }, | |
| Welcome { |
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 serde; | |
| #[macro_use] | |
| extern crate serde_derive; | |
| extern crate serde_json; | |
| #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] | |
| #[serde(tag = "tag")] | |
| pub enum A { | |
| A1 { field: B }, | |
| A2, |