This document provides an overview and introduction to the Rust programming language. It begins with a brief history of computing systems and an explanation of why Rust is being used in the course. It then covers some basic Rust constructs like if expressions and higher-order functions. It also discusses challenges like lack of documentation and provides strategies for solving programming mysteries in Rust. The document ends with an example of Rust code for a simple HTTP server.
What the &~#@<!? (Memory Management in Rust)David Evans
Operating Systems course lecture on memory management in Rust.
Browser design from 1990s (one process) to 2000s (one process per tag) to 2010s and beyond (enough processes to efficiently use machine resources to provide good user experience).
malloc, free, double-free vulnerabilities
University of Virginia
cs4414: Operating Systems
http://rust-class.org
Explicit vs. Automatic Memory Management
Garbage Collection, Reference Counting
Rust ownership types
For embedded notes, see: http://rust-class.org/class9-pointers-in-rust.html
What the &~#@<!? (Memory Management in Rust)David Evans
Operating Systems course lecture on memory management in Rust.
Browser design from 1990s (one process) to 2000s (one process per tag) to 2010s and beyond (enough processes to efficiently use machine resources to provide good user experience).
malloc, free, double-free vulnerabilities
University of Virginia
cs4414: Operating Systems
http://rust-class.org
Explicit vs. Automatic Memory Management
Garbage Collection, Reference Counting
Rust ownership types
For embedded notes, see: http://rust-class.org/class9-pointers-in-rust.html
talk at Virginia Bioinformatics Institute, December 5, 2013ericupnorth
Extensible domain-specific programming for the sciences
The notion of scientists as programmers begs the question of what sort of programming language would be a good fit. The common answer seems to be both none of them and all of them. Many scientific applications are a combination of general-purpose and domain-specific languages: R for statistical elements, MATLAB for matrix-based computations, Perl-based regular expressions for string matching, C or FORTRAN for high performance parallel computations, and scripting languages such as Python to glue them all together. This clumsy situation demonstrates the need for different domain-specific language features.
Our hypothesis is that programming could be made easier, less error-prone and result in higher-quality code if languages could be easily extended, by the programmer, with the domain-specific features that a programmer or scientists needs for their particular task at hand. This talk demonstrates the meta-language processing tools that support this composition of programmer-selected language features, with several extensions chosen from the previously mentioned list of features.
Programming with Millions of Examples (HRL)Eran Yahav
In a world where programming is largely based on using APIs, semantic code search emerges as a way to effectively learn how such APIs should be used. Towards this end, we present a formal framework for static specification mining that is able to handle code snippets and incomplete programs. Our framework analyzes code snippets and extracts partial temporal specifications. Technically, partial temporal specifications are represented as symbolic automata – automata where transitions may be labeled by variables, and a variable can be substituted by a letter, a word, or a regular language. With the help of symbolic automata, the use of the API is extracted from each snippet of code, and the many separate examples are consolidated to create a full(er) usage scenario database that can be queried. We have implemented our approach in a tool called PRIME and applied it to analyze and consolidate thousands of snippets per tested API.
This talk is based on work with Alon Mishne, Sharon Shoham, Eran Yahav, and Hongseok Yang.
In this presentation, the essence of functional programming and Event Sourcing are explained and a code example of combining these two models is shown.
This presentation by Pawel Szulc (Scala Developer) was delivered at GlobalLogic Java Conference #2 in Krakow on April 23, 2016.
IUST Advanced software engineering course by Dr. Saeed Parsa. Credits of slides belong to Dr. Saeed Parsa and IUST reverse engineering research laboratory. All slides are available publicly due to COVID 19 Pandemic.
These are the slides for the talk I gave in Harvard IQSS's "tech talk" series. The commands and files for the demo ("REPL") part of the lecture can be obtained here: http://www.mbarsinai.com/blog/2013/08/04/invitation-to-scala/.
Genomic analysis applications, libraries, and design patterns for Spark and Scala.
Presented at Scala Symposium 2017: https://conf.researchr.org/event/scala-2017/scala-2017-papers-genomic-data-analysis-in-scala-open-source-talk-
An introduction into Googles programming language Go, which had its first release in March 2012. The talk has been held at the regulars' table of the GTUG Bremen.
University of Virginia
cs4414: Operating Systems
http://rust-class.org
Explicit Memory Management
4.3BSD
Morris Worm
fingerd code
NX bit
For embedded notes, see: http://rust-class.org/class-8-managing-memory.html
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
David Evans
DC Area Crypto Day
Johns Hopkins University
30 October 2015
This (non-research) talk will start with a tutorial introduction to cryptocurrencies and how bitcoin works (and doesn’t work) today. We’ll touch on some of the legal, policy, and business aspects of bitcoin and discuss some potential research opportunities in cryptocurrencies.
talk at Virginia Bioinformatics Institute, December 5, 2013ericupnorth
Extensible domain-specific programming for the sciences
The notion of scientists as programmers begs the question of what sort of programming language would be a good fit. The common answer seems to be both none of them and all of them. Many scientific applications are a combination of general-purpose and domain-specific languages: R for statistical elements, MATLAB for matrix-based computations, Perl-based regular expressions for string matching, C or FORTRAN for high performance parallel computations, and scripting languages such as Python to glue them all together. This clumsy situation demonstrates the need for different domain-specific language features.
Our hypothesis is that programming could be made easier, less error-prone and result in higher-quality code if languages could be easily extended, by the programmer, with the domain-specific features that a programmer or scientists needs for their particular task at hand. This talk demonstrates the meta-language processing tools that support this composition of programmer-selected language features, with several extensions chosen from the previously mentioned list of features.
Programming with Millions of Examples (HRL)Eran Yahav
In a world where programming is largely based on using APIs, semantic code search emerges as a way to effectively learn how such APIs should be used. Towards this end, we present a formal framework for static specification mining that is able to handle code snippets and incomplete programs. Our framework analyzes code snippets and extracts partial temporal specifications. Technically, partial temporal specifications are represented as symbolic automata – automata where transitions may be labeled by variables, and a variable can be substituted by a letter, a word, or a regular language. With the help of symbolic automata, the use of the API is extracted from each snippet of code, and the many separate examples are consolidated to create a full(er) usage scenario database that can be queried. We have implemented our approach in a tool called PRIME and applied it to analyze and consolidate thousands of snippets per tested API.
This talk is based on work with Alon Mishne, Sharon Shoham, Eran Yahav, and Hongseok Yang.
In this presentation, the essence of functional programming and Event Sourcing are explained and a code example of combining these two models is shown.
This presentation by Pawel Szulc (Scala Developer) was delivered at GlobalLogic Java Conference #2 in Krakow on April 23, 2016.
IUST Advanced software engineering course by Dr. Saeed Parsa. Credits of slides belong to Dr. Saeed Parsa and IUST reverse engineering research laboratory. All slides are available publicly due to COVID 19 Pandemic.
These are the slides for the talk I gave in Harvard IQSS's "tech talk" series. The commands and files for the demo ("REPL") part of the lecture can be obtained here: http://www.mbarsinai.com/blog/2013/08/04/invitation-to-scala/.
Genomic analysis applications, libraries, and design patterns for Spark and Scala.
Presented at Scala Symposium 2017: https://conf.researchr.org/event/scala-2017/scala-2017-papers-genomic-data-analysis-in-scala-open-source-talk-
An introduction into Googles programming language Go, which had its first release in March 2012. The talk has been held at the regulars' table of the GTUG Bremen.
University of Virginia
cs4414: Operating Systems
http://rust-class.org
Explicit Memory Management
4.3BSD
Morris Worm
fingerd code
NX bit
For embedded notes, see: http://rust-class.org/class-8-managing-memory.html
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
David Evans
DC Area Crypto Day
Johns Hopkins University
30 October 2015
This (non-research) talk will start with a tutorial introduction to cryptocurrencies and how bitcoin works (and doesn’t work) today. We’ll touch on some of the legal, policy, and business aspects of bitcoin and discuss some potential research opportunities in cryptocurrencies.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
1. Class 2:
First Ride on Rust
cs4414 Fall 2013
University of Virginia
David Evans
2. Menu
• Recap last week, syllabus questions
• Overview of Rust (and why we are using it)
• Brief history of Computing Systems
• Some Rust constructs (for PS1)
112 September 2013 University of Virginia cs4414
3. Why learn a new
programming language?
12 September 2013 University of Virginia cs4414 2
4. J S Bach, “Coffee
Cantata”, BWV 211 (1732)
www.npj.com/homepage/teritowe/jsbhand.
html
“Jamais Jamais Jamais” from
Harmonice Musices Odhecaton
A. (1501)
5. Modern Music Notation
Roman Haubenstock-
Ramati, Concerto a Tre
John Cage, Fontana Mix
http://www.medienkunstnetz.de/works/fontana-mix/audio/1/
6.
7. Thought and Action
Languages change the way we think
BASIC: think about GOTO
Algol, Python: think about assignments, control blocks
Scheme, Haskell: think about procedures
Java, C++: think about types, objects
Languages provide abstractions of machine resources
– Hide dangerous/confusing details: memory
locations, instruction opcodes, number
representations, calling conventions, etc.
– Hiding more increases simplicity, but limits expressiveness
What do we want for systems programming?
9. Fundamental Differences
• All equivalently powerful!
– Universal languages: all capable of simulating each other
• Fundamental differences
– Expressiveness: how easy it is to describe a computation
– “Truthiness”: likelihood that a program means what a
programmer things it means
– Safeness: impact of programmer mistakes
• There is a fundamental conflict between
expressiveness and truthiness/safeness
10. Programming Language Design Space
Expressiveness
“Truthiness”
Scheme
Python
Java
C++
C
low
high
Spec#
Ada
strict typing,
static
BASIC
more mistake prone less mistake prone
print ("Hello!")
(display “Hello!”)
11. “a safe, concurrent, practical language”
12 September 2013 University of Virginia cs4414 10
Its design is oriented toward
concerns of “programming in
the large”, that is, of creating
and maintaining boundaries –
both abstract and operational
– that preserve large-system
integrity, availability and
concurrency.
from http://www.rust-lang.org/ Rust
12. 12 September 2013 University of Virginia cs4414 11
http://www.rust-lang.org/
13. 12 September 2013 University of Virginia cs4414 12
fn max(a: int, b: int) -> int {
if a > b {
a
} else {
b
}
}
fn main() {
println(fmt!("Max: %?", max(3, 4)));
}
14. Expressions and Statements
Java/C++
IfStatement ::=
if (Expression)
StatementTrue
[ else
StatementFalse
]
Rust
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
Statement ::= Expression ;
12 September 2013 University of Virginia cs4414 13
Simplified: see http://static.rust-lang.org/doc/0.7/rust.html#if-expressions for full
grammar.
Warning: “(looking for consistency in the manual's grammar is bad: it's entirely wrong in
many places.)”
15. Quiz
12 September 2013 University of Virginia cs4414 14
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
fn max(a: int, b: int) -> int {
if { } { a } else { b }
}
a) Syntax Error
b) Type Error
c) Run-time Error
16. Quiz
12 September 2013 University of Virginia cs4414 15
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
fn max(a: int, b: int) -> int {
if { } { a } else { b }
}
$ rustc block.rs
block.rs:2:7: 2:10 error: mismatched types: expected `bool` but found `()`
(expected bool but found ())
block.rs:2 if { } {
^~~
17. (Trick) Quiz
12 September 2013 University of Virginia cs4414 16
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
fn max(a: int, b: int) -> int {
if { let x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
} a) Syntax Error
b) Type Error
c) Run-time Error
18. (Trick) Quiz
12 September 2013 University of Virginia cs4414 17
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
fn max(a: int, b: int) -> int {
if { let x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
}
$ rustc block.rs
block.rs:2:23: 2:24 error: re-assignment of immutable variable `x`
block.rs:2 if { let x = 4414; x = x + a; x > b + 4414 } {
^
“Variables” are invariable…unless declared with mut.
19. Quiz
12 September 2013 University of Virginia cs4414 18
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
fn max(a: int, b: int) -> int {
if { let mut x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
}
$ rust run block.rs
Max: 5
20. Quiz
12 September 2013 University of Virginia cs4414 19
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
Statement ::= Expression ;
fn max(a: int, b: int) -> int {
if a > b { a } else { b; }
}
fn main() {
println(fmt!("Max: %?", max(5, 4)));
}
21. Quiz
12 September 2013 University of Virginia cs4414 20
fn max(a: int, b: int) -> int {
if a > b { a } else { b; }
}
fn main() {
println(fmt!("Max: %?", max(5, 4)));
}
block.rs:2:24: 2:30 error: mismatched types: expected `int` but found `()`
(expected int but found ())
block.rs:2 if a > b { a } else { b; }
^~~~~~
The semi-colon makes it a statement – no value
22. Higher-Order Functions
12 September 2013 University of Virginia cs4414 21
Java Rust
Java 8 (March 2014)
Scheme
(define (make-adder a)
(lambda (n)
(+ a n)))
| <parameters> | Block
23. 12 September 2013 University of Virginia cs4414 22
Define a function, make_adder(int), that takes
an integer as input and returns a function that
takes and int and returns the sum of the original
and input int.
make_adder(3)(1) => 4
let increment = make_adder(1);
24. 12 September 2013 University of Virginia cs4414 23
fn make_adder(a : int) -> ~fn(int) -> int {
|b| { a + b}
}
25. 12 September 2013 University of Virginia cs4414 24
Define a function, ntimes, that takes as inputs a
function f (int -> int) and an integer n, and
returns a function that applies f n-times.
fn double(a: int) -> int { a * 2 }
fn main() {
let quadruple = ntimes(double, 2);
println(fmt!("quad: %?", quadruple(2)));
}
26. 12 September 2013 University of Virginia cs4414 25
fn ntimes(f: extern fn(int) -> int, times: int) -> ~fn(int) -> int {
|x| { if times == 0 { x } else { ntimes(f, times - 1)(f(x)) } }
}
27. Reading a File
12 September 2013 University of Virginia cs4414 26
http://static.rust-lang.org/doc/0.7/std/io.html#function-file_reader
This isn’t an excerpt! This is all the documentation
there is in the Rust manual.
28. Arrgh! What to do?
12 September 2013 University of Virginia cs4414 27
Image: credit unknown
29. 12 September 2013 University of Virginia cs4414 28
“Baby”
programmer
(cs1xxx)
30. 12 September 2013 University of Virginia cs4414 29
Give up in
disgust!
34. 12 September 2013 University of Virginia cs4414 33
Caveats:
HinderRust will probably not help at all
Rust 0.7 is quite different from Rust 0.3
Easy to get lost in lots of details
Top-ranked result is not always the best solution
Dangerous to “cut-and-paste” code you don’t understand!
35. Solving Programming Mysteries
1. DuckDuckGo (or Google) is your friend!
2. stackoverflow [rust]
12 September 2013 University of Virginia cs4414 34
36. 12 September 2013 University of Virginia cs4414 35
Questions tagged with rust: 116
Questions tagged with java: 468,140
37. Solving Programming Mysteries
1. DuckDuckGo (or Google) is your friend!
2. stackoverflow [rust]
3. Experiment!
12 September 2013 University of Virginia cs4414 36
38. 12 September 2013 University of Virginia cs4414 37
fn main() {
let filereader = std::io::file_reader(~std::path::Path("test.txt"));
}
$ rustc experiment.rs
experiment.rs:6:8: 6:18 warning: unused variable: `filereader` [-W unused-variable
(default)]
experiment.rs:6 let filereader = std::io::file_reader(~std::path::Path("test.txt"));
^~~~~~~~~~
fn main() {
let filereader = std::io::file_reader(~std::path::Path("test.txt"));
println(fmt!("Reader: %?", filereader));
}
$ rust run experiment.rs
Reader: Err(~"error opening test.txt")
$ echo ‘hello’ > test.txt
$ rust run experiment.rs
warning: no debug symbols in executable (-arch x86_64)
Reader: Ok()
39. Solving Programming Mysteries
1. DuckDuckGo (or Google) is your friend!
2. stackoverflow [rust]
3. Experiment!
4. Ask for help:
– Course Piazza forum
– IRC
12 September 2013 University of Virginia cs4414 38
If you figure something useful out that is not well
documented, document it! course forum post, “blog” post
40. Back to Reading Files
12 September 2013 University of Virginia cs4414 39
Result<T, U> : enumerated type:
Ok(T)
Err(U)
Result<@Reader, ~str>
41. match expression
12 September 2013 University of Virginia cs4414 40
fn load_file(pathname : ~str) -> ~[~str] {
let filereader : Result<@Reader, ~str> =
io::file_reader(~path::Path(pathname));
match filereader {
Ok(reader) => reader.read_lines(),
Err(msg) => fail!("Cannot open file: " + msg),
}
}
How does this compare to the “Java” way?
42. match
12 September 2013 University of Virginia cs4414 41
match filereader {
Ok(reader) => reader.read_lines(),
}
compile-time completeness
cat.rs:9:4: 11:5 error: non-exhaustive patterns: Err not covered
current =
match current {
current if current % 2 == 0 => current / 2,
_ => 3 * current + 1
};
match predicates can be
arbitrary expressions
_ (like default in C
switch)
43. Why NOT to use Rust
12 September 2013 University of Virginia cs4414 42
44. 12 September 2013 University of Virginia cs4414 43
https://mail.mozilla.org/pipermail/rust-dev/2013-August/005409.html
45. 12 September 2013 University of Virginia cs4414 44
https://github.com/graydon/rust/wiki
This is a very preliminary work in
progress. No supported releases yet
nor defined release schedule /
plans. Caveat emptor. It will crash. It
will change syntax and semantics. It
will eat your laundry. Use at your
own risk. Etc.
Originally posted: 15 Dec 2011 (but still there today)
46. Rust or Bust?
Rust
Immature, Unstable
Poorly documented
Few open source
projects (except Servo)
Not in high employer
demand
No other courses
Bust (C)
Mature, Stable
Hundreds of books, etc.
Lots of open source
projects (incl. Linux)
Popular for interview
questions
Nearly all OS courses
12 September 2013 University of Virginia cs4414 45
47. Rust or Bust?
Rust
Benefits from past 30
years of language and
compiler research
Bust (C)
Suffers from
maintaining backwards
compatibility with
language stripped down
to fit in ~9 KB
12 September 2013 University of Virginia cs4414 46
48. 12 September 2013 University of Virginia cs4414 47
PDP-11
Ken Thompson
Dennis Ritchie PDP-11
~4KB of memory
49. 12 September 2013 University of Virginia cs4414 48
“I call it my billion-
dollar mistake.”(Sir
Tony Hoare)
int main(int argc, char **argv) {
char *s = (char *) malloc (MY_SIZE);
*s = 'a';
return 0;
}
Photo: Bertrand Meyer
$ gcc -Wall null.c
$ ./a.out
Segmentation fault (core dumped)
Note: Sir Tony invented null references in 1964 (before C), and said this in 2009
(back when an American billion dollars was still real money). See a great talk here:
http://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare
He designed compiler to check every reference is safe (but null and bounds checking), but C
removed them as too expensive.
50. Rust or Bust?
Rust
Benefits from past 30
years of language and
compiler research
Chance to influence a
new, exciting, fast-
evolving language
Some really cool features
for memory
management and
concurrency
FUN!
Bust (C)
Suffers from maintaining
backwards compatibility
C++0x standard process
began in 1998, released in
2011, over 40 meetings
Lots of complexity, but
not designed for safety
Boring, Annoying
12 September 2013 University of Virginia cs4414 49
51. Diving In: zhttpo.rs
12 September 2013 University of Virginia cs4414 50
// zhttpto.rs
// ...
extern mod extra;
use extra::uv;
use extra::{net_ip, net_tcp};
use std::str;
static BACKLOG: uint = 5;
static PORT: uint = 4414;
static IPV4_LOOPBACK: &'static str = "127.0.0.1";
fn new_connection_callback(new_conn :net_tcp::TcpNewConnection, _killch:
std::comm::SharedChan<Option<extra::net_tcp::TcpErrData>>)
{
...
Comments similar to C++
Dependency on an external “crate” (compilation unit)
Import into namespace:
uv = “extra::uv”
global “variables” (no mut, so
they are constants)
52. main
12 September 2013 University of Virginia cs4414 51
fn main() {
net_tcp::listen(net_ip::v4::parse_addr(IPV4_LOOPBACK), PORT, BACKLOG,
&uv::global_loop::get(),
|_chan| { println(fmt!("Listening on tcp port %u ...", PORT)); },
new_connection_callback);
}
53. 12 September 2013 University of Virginia cs4414 52
http://static.rust-lang.org/doc/std/net_tcp.html#function-listen
54. 12 September 2013 University of Virginia cs4414 53
fn main() {
net_tcp::listen(net_ip::v4::parse_addr(IPV4_LOOPBACK), PORT, BACKLOG,
&uv::global_loop::get(),
|_chan| { println(fmt!("Listening on tcp port %u ...", PORT)); },
new_connection_callback);
}
on_establish_cb: ~fn(SharedChan<Option<TcpErrData>>)
a callback that is evaluated if/when the listener is successfully
established. it takes no parameters
new_connect_cb - a callback to be evaluated, on the libuv thread, whenever a client
attempts to connect on the provided ip/port. the callback’s arguments are: …
55. 12 September 2013 University of Virginia cs4414 54
fn new_connection_callback(new_conn : net_tcp::TcpNewConnection,
_killch : std::comm::SharedChan<…>)
{
do spawn {
let accept_result = extra::net_tcp::accept(new_conn);
match accept_result {
Err(err) => { println(fmt!("Connection error: %?", err)); },
Ok(sock) => {
let peer_addr: ~str = net_ip::format_addr(&sock.get_peer_addr());
println(fmt!("Received connection from: %s", peer_addr));
let read_result = net_tcp::read(&sock, 0u);
match read_result {
Err(err) => { println(fmt!("Receive error: %?", err)); },
Ok(bytes) => {
let request_str = str::from_bytes(bytes.slice(0, bytes.len() - 1));
println(fmt!("Request received:n%s", request_str));
let response: ~str = ~
"HTTP/1.1 …”;
net_tcp::write(&sock, response.as_bytes_with_null_consume());
},
};
} } }; }
56. Charge
• You should be making progress on PS1 now:
you know everything you need to finish it
– Take advantage of Piazza forum and IRC for any
strange Rustiness you encounter
• Next class: processes!
12 September 2013 University of Virginia cs4414 55
57. Ways to Learn New Languages
• Read the compiler source code
• Read the reference manual
• Go through a (well designed!) tutorial
• Read a good book with lots of exercises
• Dive right into a complex program and try to
modify it
• Find a mentor who is a language expert
12 September 2013 University of Virginia cs4414 56