No notes.
FOMO
Breaking point
Wisdom
The `Constellation`, Servo's Grand Central Station
The constellation tracks all information kept globally
by the browser engine, which includes:
* The set of all `EventLoop` objects.
* The set of all `Pipeline` objects.
* The set of all `BrowsingContext` objects.
+------------+ +------------+ +---------+
| Browsing | ------parent?------> | Pipeline | --event_loop--> | Event |
| Context | ------current------> | | | Loop |
| | ------prev*--------> | | <---pipeline*-- | |
| | ------next*--------> | | +---------+
| | | |
| | <-top_level--------- | |
| | <-browsing_context-- | |
+------------+ +------------+
[…] software designed to provide a platform for other software
programming when details matter
all that stuff that is still written in C/C++ (or Rust)
[…] it’s not a category […] but a way of looking at the problem […] a model that recognizes the bottom layer of the API
andrewrk
What is different about systems programming?
Many things: precise control over data layout, memory management, raw access to hardware, ...
Hey, hey, hey...
Just say "performance"
struct Person {
employee_id: usize,
shirt_color: [u8; 3]
}
let contents = std::fs::read_to_string("config.json")?;
foo_read_something(&contents);
fn foo_read_something(source: &str) {
// ...
}
fn bar_traverse_something(iter: impl IntoIterator) {
/* ... */
}
bar_traverse_something(vec![1, 2, 3]);
bar_traverse_something(&['a', 'b', '💩']);
std::thread::spawn(|| {
do_stuff();
});
fn poll(fut: Pin<&mut Fut>) -> /* ... */ {
unsafe {
let data = fut.get_unchecked_mut();
data.do_something();
}
}
let name: &str = "Jia Tan";
let owned: String = name.to_string();
let c_name: CString = CString::new(name)?;
let os_name: OSString = OsString::from(owned);
let path_name: &Path = Path::new(name);
bool p;
if (p) {
puts("p is true");
}
if (!p) {
puts("p is false");
}
p is true
p is false
🙃🙃🙃🙃
vector<char> v(1, 'a');
char* first = &v[0];
v.push_back('b');
v.push_back('c');
std::cout << "*first (v[0]) = " << *first << std::endl;
If after the operation the new size() is greater than old capacity() a reallocation takes place, in which case all iterators (including the end() iterator) and all references to the elements are invalidated. Otherwise only the end() iterator is invalidated
let mut v = vec!['a'];
let first = &v[0];
v.push('b');
v.push('c');
println!("first (v[0]) = {first}");
error: cannot borrow `v` as mutable because it is also borrowed as immutable
|
| let first = &v[0];
| - immutable borrow occurs here
|
| v.push('b');
| ^^^^^^^^^^^ mutable borrow occurs here
...
| println!("first (v[0]) = {first}");
| ------- immutable borrow later used here
let mut counter = 0;
let shared = &mut counter;
for _ in 0..10 {
std::thread::spawn(|| {
*shared += 1;
});
}
error: two closures require unique access to `*shared` at the same time
|
| std::thread::spawn(|| {
| - ^^ closures are constructed here in different iterations of loop
| ___|
| |
| | *shared += 1;
| | ------- borrows occur due to use of `*shared` in closure
| | });
| |____- argument requires that `*shared` is borrowed for `'static`
#[derive(FromForm)]
struct Options<'r> {
name: Option<&'r str>,
}
#[get("/?<opt..>")]
fn hello(opt: Options<'_>) -> String {
match opt.name {
Some(name) => format!("Hello, {name}!"),
None => String::from("Hello!")
}
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![hello])
}
let api_key = match std::env::var("API_KEY") {
Ok(key) => key,
Err(VarError::NotPresent) =
bail!("Please provide api key as API_KEY"),
Err(VarError::NotUnicode(..)) =>
bail!("API_KEY must be valid unicode"),
};
$ cargo new commit-conf && cd commit-conf
Created binary (application) `commit-conf` package
$ cargo run
Compiling commit-conf v0.1.0 (/commit-conf)
Finished dev [unoptimized] target(s) in 0.19s
Running `target/debug/commit-conf`
Hello, world!
$ cargo test
Finished test [unoptimized] target(s) in 0.00s
Running unittests src/lib.rs
running 1 test
test tests::it_works ... ok
test result: ok. 1 passed; 0 failed;
top
, vim
, less
ratatui