Skip to content

Instantly share code, notes, and snippets.

@JarrettBillingsley
Created December 13, 2013 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JarrettBillingsley/7939420 to your computer and use it in GitHub Desktop.
Save JarrettBillingsley/7939420 to your computer and use it in GitHub Desktop.
type ValNum = f64;
type ValStr = Rc<~str>;
#[deriving(Clone)]
enum Value
{
Null,
Bool(bool),
Num(ValNum),
String(ValStr),
}
// And later...
// self.stack is of type ~[Value]
print!("{}", match self.stack[i]
{
Null => ~"null",
Bool(b) => b.to_str(),
Num(n) => n.to_str(),
String(s) => s.borrow().as_slice()
});
@JarrettBillingsley
Copy link
Author

This gives me:

main.rs:286:16: 292:4 error: match arms have incompatible types: expected `~str` but found `&str` (str storage differs: expected ~ but found &)
main.rs:286                     print!("{}", match self.stack[i]
main.rs:287                     {
main.rs:288                             Null => ~"null",
main.rs:289                             Bool(b) => b.to_str(),
main.rs:290                             Num(n) => n.to_str(),
main.rs:291                             String(s) => s.borrow().as_slice()
            ...

@JarrettBillingsley
Copy link
Author

main.rs:291:4: 291:13 error: cannot move out of dereference of & pointer
main.rs:291                             String(s) => print!("{}", s.borrow().as_slice())
                                        ^~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment