Merge pull request #126 from bvssvni/master

Update to latest Rust
This commit is contained in:
Tony Aldridge
2014-06-15 17:34:06 +01:00
3 changed files with 20 additions and 20 deletions
+12 -12
View File
@@ -110,7 +110,7 @@ pub fn generate_branchified_method(
end: &str, max_len: &str, valid: &str, unknown: &str) {
for &c in branch.matches.iter() {
let next_prefix = format!("{}{}", prefix, c as char);
wf!("Some(b) if b == '{}' as u8 => match {} \\{", c as char, read_call);
wf!("Some(b) if b == '{}' as u8 => match {} {{", c as char, read_call);
for b in branch.children.iter() {
r(writer, b, next_prefix.as_slice(), indent + 1, read_call, end, max_len, valid, unknown);
}
@@ -121,30 +121,30 @@ pub fn generate_branchified_method(
}
wf!(" Some(b) if {} => (\"{}\", b),", valid, next_prefix.as_slice());
wf!(" _ => return None,");
wf!("\\},");
wf!("}},");
}
}
wf!("let (s, next_byte) = match {} \\{", read_call);
wf!("let (s, next_byte) = match {} {{", read_call);
for b in branches.iter() {
r(writer, b, "", indent + 1, read_call, end, max_len, valid, unknown);
}
wf!(" Some(b) if {} => (\"\", b),", valid);
wf!(" _ => return None,");
wf!("\\};");
wf!("}};");
wf!("// OK, that didn't pan out. Let's read the rest and see what we get.");
wf!("let mut s = s.to_string();");
wf!("s.push_char(next_byte as char);");
wf!("loop \\{");
wf!(" match {} \\{", read_call);
wf!("loop {{");
wf!(" match {} {{", read_call);
wf!(" Some(b) if b == {} => return Some({}),", end, unknown.replace("{}", "s"));
wf!(" Some(b) if {} => \\{", valid);
wf!(" if s.len() == {} \\{", max_len);
wf!(" Some(b) if {} => {{", valid);
wf!(" if s.len() == {} {{", max_len);
wf!(" // Too long; bad request");
wf!(" return None;");
wf!(" \\}");
wf!(" }}");
wf!(" s.push_char(b as char);");
wf!(" \\},");
wf!(" }},");
wf!(" _ => return None,");
wf!(" \\}");
wf!("\\}");
wf!(" }}");
wf!("}}");
}
+4 -4
View File
@@ -345,9 +345,9 @@ impl ToPrimitive for KeyCode {
".as_bytes()));
let types = vec!("i64", "u64", "int");
for primitive_type in types.iter() {
try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{
try!(out.write(format!("fn to_{}(&self) -> Option<{}> {{
Some(self.code() as {})
\\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
}}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
}
try!(out.write("
@@ -363,8 +363,8 @@ impl FromPrimitive for KeyCode {
".as_bytes()));
for primitive_type in types.iter() {
try!(out.write(format!("
fn from_{}(n: {}) -> Option<KeyCode> \\{
match n \\{
fn from_{}(n: {}) -> Option<KeyCode> {{
match n {{
", *primitive_type, *primitive_type).container_as_bytes()));
for &entry in entries.iter() {
try!(out.write(format!(" {} => Some({}),\n", entry.code, entry.ident()).container_as_bytes()));
+4 -4
View File
@@ -355,9 +355,9 @@ impl ToPrimitive for ScanCode {
let types = vec!("i64", "u64", "int");
for primitive_type in types.iter() {
try!(out.write(format!("fn to_{}(&self) -> Option<{}> \\{
try!(out.write(format!("fn to_{}(&self) -> Option<{}> {{
Some(self.code() as {})
\\}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
}}\n", *primitive_type, *primitive_type, *primitive_type).container_as_bytes()));
}
try!(out.write("
@@ -374,8 +374,8 @@ impl FromPrimitive for ScanCode {
for primitive_type in types.iter() {
try!(out.write(format!("
fn from_{}(n: {}) -> Option<ScanCode> \\{
match n \\{
fn from_{}(n: {}) -> Option<ScanCode> {{
match n {{
", *primitive_type, *primitive_type).container_as_bytes()));
for &entry in entries.iter() {