Skip to content

Instantly share code, notes, and snippets.

@5nyper
Last active August 29, 2015 14:11
Show Gist options
  • Save 5nyper/c0001e08077cf9dddd42 to your computer and use it in GitHub Desktop.
Save 5nyper/c0001e08077cf9dddd42 to your computer and use it in GitHub Desktop.
The Tragic death, of str :(
extern crate serialize;
use std::io;
fn main() {
use serialize::{Decodable, Encodable, json};
use serialize::json::PrettyEncoder;
println!("*******/// Agenda \\\\\\*******(v.0.0.1)");
println!("Developed by Karim Ellaisy, Written in Rust\n\n");
println!("Enter Class name first, then enter stuff for it.");
let mut stdin = io::stdin();
let (mut class1,mut class2,mut class3,mut class4,mut class5,mut class6,mut class7,mut class8) = (" ".to_string(), " ".to_string()," ".to_string()," ".to_string()," ".to_string()," ".to_string()," ".to_string()," ".to_string());
let mut reader = stdin.lock();
for line in reader.lines() {
let srt = line.unwrap();
let v: Vec<_> = srt.splitn(1,' ').collect();
match v[0].trim() {
"Java" => {
class1 = v[1].to_string();
}
/* "Latin"|"latin" => {
class2 = srt.as_slice().trim().nth();
}
"Math"|"math" => {
class3 = srt.as_slice().trim().nth();
}
"english"|"English" => {
class4 = srt.as_slice().trim().nth();
}
"PRM"|"prm" => {
class5 = srt.as_slice().trim().nth();
}
"history" => {
class6 = srt.as_slice().trim().nth();
}
"Health"|"health" => {
class7 = srt.as_slice().trim().nth();
}
"Chemistry"|"chemistry"|"chem" => {
class8 = srt.as_slice().trim().nth();
} */
"done" => println!("sup"),
_ => println!("Input Invalid! from the outer braces"),
}
#[deriving(Encodable)]
struct Agenda {
AP_Java: String,
Latin_III: String,
Algebra_II: String,
Honors_English: String,
PRM: String,
Honors_History: String,
Health: String,
Chemistry: String,
}
let mut user = Agenda {
AP_Java: class1,
Latin_III: class2,
Algebra_II: class3,
Honors_English: class4,
PRM: class5,
Honors_History: class6,
Health: class7,
Chemistry: class8,
};
let mut buffer: Vec<u8> = Vec::new();
{
let mut encoder = PrettyEncoder::new(&mut buffer);
user.encode(&mut encoder).ok().expect("JSON encode error");
}
let encoded = String::from_utf8(buffer).unwrap();
println!("{}", encoded);
}
}
So Im tryin to create practical apps in Rust to learn it, so I'm creating an Agenda(which ill add GUI later), this is what I have so far:
What am I tryinf to do right now? Im trying to add the input options to add the stuff u have to do with each class. so If I input
`Java, Do wkst 1 and 2` the match case will match Java, then take the rest and mutate class1 with whats after `Java` and so on with other classes.
Whats the problem though?
This is the error Im getting:
$ rustc test.rs
test.rs:56:14: 56:20 error: use of moved value: `class1`
test.rs:56 AP_Java: class1,
^~~~~~
test.rs:56:14: 56:20 note: `class1` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:56 AP_Java: class1,
^~~~~~
test.rs:57:16: 57:22 error: use of moved value: `class2`
test.rs:57 Latin_III: class2,
^~~~~~
test.rs:57:16: 57:22 note: `class2` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:57 Latin_III: class2,
^~~~~~
test.rs:58:17: 58:23 error: use of moved value: `class3`
test.rs:58 Algebra_II: class3,
^~~~~~
test.rs:58:17: 58:23 note: `class3` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:58 Algebra_II: class3,
^~~~~~
test.rs:59:21: 59:27 error: use of moved value: `class4`
test.rs:59 Honors_English: class4,
^~~~~~
test.rs:59:21: 59:27 note: `class4` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:59 Honors_English: class4,
^~~~~~
test.rs:60:10: 60:16 error: use of moved value: `class5`
test.rs:60 PRM: class5,
^~~~~~
test.rs:60:10: 60:16 note: `class5` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:60 PRM: class5,
^~~~~~
test.rs:61:21: 61:27 error: use of moved value: `class6`
test.rs:61 Honors_History: class6,
^~~~~~
test.rs:61:21: 61:27 note: `class6` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:61 Honors_History: class6,
^~~~~~
test.rs:62:13: 62:19 error: use of moved value: `class7`
test.rs:62 Health: class7,
^~~~~~
test.rs:62:13: 62:19 note: `class7` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:62 Health: class7,
^~~~~~
test.rs:63:16: 63:22 error: use of moved value: `class8`
test.rs:63 Chemistry: class8,
^~~~~~
test.rs:63:16: 63:22 note: `class8` moved here because it has type `collections:
:string::String`, which is non-copyable
test.rs:63 Chemistry: class8,
^~~~~~
error: aborting due to 8 previous errors
Any Help? Thanks in advance!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment