Skip to content

Commit

Permalink
Update for latest rust.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nercury committed May 4, 2015
1 parent b1387c8 commit a1b5c53
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/demux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ pub trait ChannelHandler {
impl ChannelHandler for () {}


#[derive(Copy)]
#[derive(Clone)]
pub struct TelnetDemuxState {
pub qstate: [QState; 256],
pub qstate: Vec<QState>,
pub active_channel: Option<u8>,
}
impl TelnetDemuxState {
pub fn new() -> TelnetDemuxState {
TelnetDemuxState {
qstate: [QState::new(); 256],
qstate: vec![QState::new(); 256],
active_channel: None,
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(slicing_syntax, globs, unboxed_closures, associated_types)]

pub mod carrier;

pub mod parser;
Expand Down
26 changes: 13 additions & 13 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use self::ParseState::*;

#[derive(Copy, Show)]
#[derive(Copy, Clone, Debug)]
pub enum ParseState {
Neutral,
Carriage,
Command,
Subchannel(u8),
}

#[derive(Show)]
#[derive(Debug)]
pub enum TelnetToken<'a> {
Text(&'a [u8]),
Command(u8),
Expand All @@ -29,7 +29,7 @@ impl TelnetTokenizer {
pub fn new() -> TelnetTokenizer {
TelnetTokenizer {
state: ParseState::Neutral,
is_long_command: box |cmd| 250 <= cmd && cmd <= 254,
is_long_command: Box::new(|cmd| 250 <= cmd && cmd <= 254),
}
}

Expand All @@ -52,27 +52,27 @@ type ParseResult<'b> = (Option<TelnetToken<'b>>, ParseState, &'b [u8]);
impl<'a, 'b> TokenStream<'a, 'b> {
fn carriage_state(&self) -> ParseResult<'b> {
if self.data[0] == b'\n' {
(Some(TelnetToken::Text(b"\r\n")), Neutral, self.data[1..])
(Some(TelnetToken::Text(b"\r\n")), Neutral, &self.data[1..])
} else if self.data[0] == b'\0' {
(Some(TelnetToken::Text(b"\r")), Neutral, self.data[1..])
(Some(TelnetToken::Text(b"\r")), Neutral, &self.data[1..])
} else {
// invalid stream, technically, but still unambiguous
(Some(TelnetToken::Text(b"\r")), Neutral, self.data)
(Some(TelnetToken::Text(b"\r")), Neutral, &self.data)
}
}

fn command_state(&self) -> ParseResult<'b> {
if (*self.context.is_long_command).call((self.data[0],)) {
(None, Subchannel(self.data[0]), self.data[1..])
if (*self.context.is_long_command)(self.data[0]) {
(None, Subchannel(self.data[0]), &self.data[1..])
} else if self.data[0] == b'\xFF' {
(Some(TelnetToken::Text(b"\xFF")), Neutral, self.data[1..])
(Some(TelnetToken::Text(b"\xFF")), Neutral, &self.data[1..])
} else {
(Some(TelnetToken::Command(self.data[0])), Neutral, self.data[1..])
(Some(TelnetToken::Command(self.data[0])), Neutral, &self.data[1..])
}
}

fn subchannel_state(&self, command: u8) -> ParseResult<'b> {
(Some(TelnetToken::Negotiation{command: command, channel: self.data[0]}), Neutral, self.data[1..])
(Some(TelnetToken::Negotiation{command: command, channel: self.data[0]}), Neutral, &self.data[1..])
}

fn neutral_state(&self) -> ParseResult<'b> {
Expand All @@ -85,7 +85,7 @@ impl<'a, 'b> TokenStream<'a, 'b> {
let token = if idx == 0 {
None
} else {
Some(TelnetToken::Text(self.data[0..idx]))
Some(TelnetToken::Text(&self.data[0..idx]))
};

let state = if self.data[idx] == b'\r' {
Expand All @@ -94,7 +94,7 @@ impl<'a, 'b> TokenStream<'a, 'b> {
Command
};

(token, state, self.data[idx+1..])
(token, state, &self.data[idx+1..])
}
None => {
// This whole data block is text.
Expand Down
6 changes: 3 additions & 3 deletions src/qstate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]

#[derive(Show, Copy, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum QStateUni {
Disabled,
AwaitEnable,
Expand All @@ -18,13 +18,13 @@ impl QStateUni {
}
}

#[derive(Show, Copy)]
#[derive(Debug, Copy, Clone)]
pub enum QAttitude {
Local,
Remote,
}

#[derive(Show, Copy)]
#[derive(Debug, Copy, Clone)]
pub struct QState {
pub local: QStateUni,
pub remote: QStateUni,
Expand Down
4 changes: 2 additions & 2 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ where Parent: ChannelHandler {
pub struct EndpointRegistry<'parent, Parent: 'parent> {
pub parent: &'parent mut Parent,

pub command_map: HashMap<u8, uint>,
pub channel_map: HashMap<u8, uint>,
pub command_map: HashMap<u8, usize>,
pub channel_map: HashMap<u8, usize>,
pub endpoints: Vec<&'parent mut (TelnetChannel<Parent> + 'parent)>,

pub main: Option<&'parent mut (TelnetChannel<Parent> + 'parent)>,
Expand Down

0 comments on commit a1b5c53

Please sign in to comment.