Update typst

This commit is contained in:
Thomas Forgione 2023-04-14 18:43:18 +02:00
parent a3bb4648ca
commit 6fa2bff614
3 changed files with 16 additions and 18 deletions

View File

@ -1,2 +1,2 @@
all:
mkdir -p build && typst main.typ build/main.pdf
mkdir -p build && typst compile main.typ build/main.pdf

View File

@ -24,7 +24,7 @@ It provides classes to deal with everything we need:
- the *Geometry* and *BufferGeometry* classes are the classes that hold the vertex buffers, we will discuss it more in the next paragraph;
- the *Material* class is the class that holds the properties used to render geometry (the most important information being the texture), there are many classes derived from Material, and the developer can choose what material they want for their objects;
- the *Mesh* class is the class that links the geometry and the material, it derives the Object class and can thus be added to a scene and rendered.
A snippet of the basic usage of these classes is given in @three-hello-world. // TODO
A snippet of the basic usage of these classes is given in @three-hello-world.
#figure(
align(left,
@ -88,7 +88,7 @@ There are two types of borrow, the immutable borrow and the mutable borrow (roug
The compiler comes with the _borrow checker_ which makes sure you only use variables that you are allowed to use.
For example, the owner can only use the value if it is not being borrowed, and it is only possible to either mutably borrow a value once, or immutably borrow a value many times.
At first, the borrow checker seems particularly efficient to detect bugs in concurrent software, but in fact, it is also decisive in non concurrent code.
Consider the piece of C++ code in Snippets X and Y. // TODO
Consider the piece of C++ code in @undefined-behaviour-cpp and @undefined-behaviour-it-cpp.
#figure(
align(left,
@ -115,7 +115,7 @@ for (auto it = std::begin(vec); it < std::end(vec); it++)
This loop should go endlessly because the vector grows in size as we add elements in the loop.
But the most important thing here is that since we add elements to the vector, it will eventually need to be reallocated, and that reallocation will invalidate the iterator, meaning that the following iteration will provoke an undefined behaviour.
The equivalent code in Rust is in @undefined-behaviour-rs and @undefined-behaviour-it-rs. // TODO
The equivalent code in Rust is in @undefined-behaviour-rs and @undefined-behaviour-it-rs.
#columns(2, gutter: 11pt)[
#v(0.8cm)
@ -153,7 +153,7 @@ loop {
What happens is that the iterator needs to borrow the vector.
Because it is borrowed, it can no longer be borrowed as mutable since mutating it could invalidate the other borrowers.
And effectively, the borrow checker will crash the compiler with the error in Snippet X. // TODO
And effectively, the borrow checker will crash the compiler with the error in @undefined-behaviour-error.
#figure(
align(left,
@ -171,7 +171,7 @@ error[E0502]: cannot borrow `vec` as mutable because it is also borrowed as immu
```
),
caption: [Error given by the compiler on @undefined-behaviour-rs],
)
)<undefined-behaviour-error>
This example is one of the many examples of how powerful the borrow checker is: in Rust code, there can be no dangling reference, and all the segmentation faults coming from them are detected by the compiler.
The borrow checker may seem like an enemy to newcomers because it often rejects code that seem correct, but once they get used to it, they understand what is the problem with their code and either fix the problem easily, or realize that the whole architecture is wrong and understand why.

View File

@ -3,17 +3,15 @@
#show link: underline
// Code formatting
#show raw.where(block: false): box.with(
fill: luma(240),
inset: (x: 3pt, y: 0pt),
outset: (y: 3pt),
radius: 2pt,
)
#show raw.where(block: true): block.with(
fill: luma(240),
inset: 10pt,
radius: 4pt,
)
#show raw.where(block: true): it => { set par(justify: false); grid(
columns: (100%, 100%),
column-gutter: -100%,
block(width: 100%, inset: 1em, for (i, line) in it.text.split("\n").enumerate() {
box(width: 0pt, align(right, str(i + 1) + h(2em)))
hide(line)
linebreak()
}),
block(radius: 1em, fill: luma(246), width: 100%, inset: 1em, it),
)}
#include "foreword/main.typ"