Closed
Description
Been trying to get my code working with the latest rust (master from July 22) and am stymied by the code below:
// rustc --lib owned.rs
type parser<T: copy> = fn@ (state) -> status<T>;
type state = {file: ~str, text: @[char], index: uint, line: int};
type status<T: copy> = result::result<succeeded<T>, failed>;
type succeeded<T: copy> = {new_state: state, value: T};
type failed = {old_state: state, err_state: state, mesg: ~str};
fn return<T: copy>(value: T) -> parser<T>
{
|input: state|
{
result::ok({new_state: input, value: value})
}
}
fn thene<T: copy, U: copy>(parser: parser<T>, eval: fn@ (T) -> parser<U>) -> parser<U>
{
|input: state|
{
do result::chain(parser(input))
|pass|
{
do result::chain_err(eval(pass.value)(pass.new_state))
|failure|
{
result::err({old_state: input with failure})
}
}
}
}
fn compose<T: copy, U: copy>(parser: parser<T>, op: parser<U>) -> parser<(U, T)>
{
do thene(op)
|operator|
{
do thene(parser)
|value|
{
return((operator, value))
}
}
}
// owned.rs:16:39: 16:44 error: value may contain borrowed pointers; use `owned` bound
// owned.rs:16 result::ok({new_state: input, value: value})
// ^~~~~
// Note that I can't use an owned bound because owned does not imply copy.
Barring a complete rewrite, I don't see any way I can get the compiler to accept the code.
Metadata
Metadata
Assignees
Labels
No labels