pub struct Code<S: AsRef<str>> {
pub lines: Vec<CodeLine<S>>,
}
Fields§
§lines: Vec<CodeLine<S>>
Implementations§
Source§impl<S: AsRef<str>> Code<S>
impl<S: AsRef<str>> Code<S>
Sourcepub fn transpile(&self) -> String
pub fn transpile(&self) -> String
Examples found in repository?
examples/hello_world.rs (line 20)
8fn main() -> io::Result<()> {
9 let c = Code {
10 lines: vec![
11 CodeLine::Printf(vec![String("Hello, "), String("world\n")]),
12 CodeLine::Scanf {
13 name: "input",
14 prompt: "How are you? ",
15 },
16 CodeLine::Printf(vec![String("So you are "), Ident("input"), String("\n")]),
17 ],
18 };
19
20 println!("{}", c.transpile());
21 c.export_c("examples/hello_world.c")?;
22
23 match c.build("examples/hello_world") {
24 Ok(_) => Ok(()),
25 Err(e) => {
26 panic!("{e}")
27 }
28 }
29}
Sourcepub fn export_c<P: AsRef<Path>>(&self, path: P) -> Result<()>
pub fn export_c<P: AsRef<Path>>(&self, path: P) -> Result<()>
Examples found in repository?
examples/hello_world.rs (line 21)
8fn main() -> io::Result<()> {
9 let c = Code {
10 lines: vec![
11 CodeLine::Printf(vec![String("Hello, "), String("world\n")]),
12 CodeLine::Scanf {
13 name: "input",
14 prompt: "How are you? ",
15 },
16 CodeLine::Printf(vec![String("So you are "), Ident("input"), String("\n")]),
17 ],
18 };
19
20 println!("{}", c.transpile());
21 c.export_c("examples/hello_world.c")?;
22
23 match c.build("examples/hello_world") {
24 Ok(_) => Ok(()),
25 Err(e) => {
26 panic!("{e}")
27 }
28 }
29}
Sourcepub fn build<O: AsRef<OsStr>>(&self, path: O) -> Result<NamedTempFile>
pub fn build<O: AsRef<OsStr>>(&self, path: O) -> Result<NamedTempFile>
Examples found in repository?
examples/hello_world.rs (line 23)
8fn main() -> io::Result<()> {
9 let c = Code {
10 lines: vec![
11 CodeLine::Printf(vec![String("Hello, "), String("world\n")]),
12 CodeLine::Scanf {
13 name: "input",
14 prompt: "How are you? ",
15 },
16 CodeLine::Printf(vec![String("So you are "), Ident("input"), String("\n")]),
17 ],
18 };
19
20 println!("{}", c.transpile());
21 c.export_c("examples/hello_world.c")?;
22
23 match c.build("examples/hello_world") {
24 Ok(_) => Ok(()),
25 Err(e) => {
26 panic!("{e}")
27 }
28 }
29}
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Code<S>
impl<S> RefUnwindSafe for Code<S>where
S: RefUnwindSafe,
impl<S> Send for Code<S>where
S: Send,
impl<S> Sync for Code<S>where
S: Sync,
impl<S> Unpin for Code<S>where
S: Unpin,
impl<S> UnwindSafe for Code<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more