Skip to content

Instantly share code, notes, and snippets.

@unfo
Created December 21, 2014 18:37
Show Gist options
  • Save unfo/5ea21e04bd6698f5da55 to your computer and use it in GitHub Desktop.
Save unfo/5ea21e04bd6698f5da55 to your computer and use it in GitHub Desktop.
Compiling fastgraph v0.0.1 (file:///Users/jw/fun/rust/fastgraph)
/Users/jw/fun/rust/fastgraph/src/lib.rs:18:4: 24:5 error: match arms have incompatible types: expected `()`, found `core::option::Option<<generic #127>>` (expected (), found enum core::option::Option)
/Users/jw/fun/rust/fastgraph/src/lib.rs:18 match re.find(line) {
/Users/jw/fun/rust/fastgraph/src/lib.rs:19 Some((from,end)) => {
/Users/jw/fun/rust/fastgraph/src/lib.rs:20 let i: int = from_str(line.slice(from,end)).unwrap();
/Users/jw/fun/rust/fastgraph/src/lib.rs:21 Some(i);
/Users/jw/fun/rust/fastgraph/src/lib.rs:22 },
/Users/jw/fun/rust/fastgraph/src/lib.rs:23 _ => None
...
/Users/jw/fun/rust/fastgraph/src/lib.rs:23:10: 23:14 note: match arm with an incompatible type
/Users/jw/fun/rust/fastgraph/src/lib.rs:23 _ => None
^~~~
/Users/jw/fun/rust/fastgraph/src/lib.rs:36:2: 46:3 error: match arms have incompatible types: expected `()`, found `core::option::Option<<generic #16>>` (expected (), found enum core::option::Option)
/Users/jw/fun/rust/fastgraph/src/lib.rs:36 match (from,to,weight) {
/Users/jw/fun/rust/fastgraph/src/lib.rs:37 (Some(f), Some(t), Some(w)) => {
/Users/jw/fun/rust/fastgraph/src/lib.rs:38 let v: Vertice = Vertice {
/Users/jw/fun/rust/fastgraph/src/lib.rs:39 source: f,
/Users/jw/fun/rust/fastgraph/src/lib.rs:40 target: t,
/Users/jw/fun/rust/fastgraph/src/lib.rs:41 weight: w
...
/Users/jw/fun/rust/fastgraph/src/lib.rs:45:8: 45:12 note: match arm with an incompatible type
/Users/jw/fun/rust/fastgraph/src/lib.rs:45 _ => None
^~~~
extern crate regex;
use regex::Regex;
struct Vertice {
source: int,
target: int,
weight: int,
}
struct Node {
id: int,
vertices: Vec<Vertice>,
}
fn regexp_int(line: &str, re: &str) -> Option<int> {
match Regex::new(re) {
Ok(re) => {
match re.find(line) {
Some((from,end)) => {
let i: int = from_str(line.slice(from,end)).unwrap();
Some(i);
},
_ => None
}
},
Err(_) => None
}
}
pub fn parse_node(line: &str) -> Option<Vertice> {
let from = regexp_int(line, "\"from\": (\\d+)");
let to = regexp_int(line, "\"to\": (\\d+)");
let weight = regexp_int(line, "\"weight\": (\\d+)");
match (from,to,weight) {
(Some(f), Some(t), Some(w)) => {
let v: Vertice = Vertice {
source: f,
target: t,
weight: w
};
Some(v);
},
_ => None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment