Skip to content

Commit f7ef94a

Browse files
authored
doc: rewrite book intro (#389)
1 parent 611f693 commit f7ef94a

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

book/src/introduction.md

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,62 @@
11
# Introduction <img align="right" width="73" height="45" src="https://raw.githubusercontent.com/tskit-dev/administrative/main/logos/svg/tskit-rust/Tskit_rust_logo.eps.svg">
22

3-
## Do you need `tskit-rust`?
3+
## Required background.
4+
5+
* We assume familiarity with `tskit`. See [tskit.dev](https://tskit.dev).
6+
* Comfort with rust is required.
7+
* [The book](https://doc.rust-lang.org/book/) is a good place to start.
8+
* [The Rustonomicon](https://doc.rust-lang.org/nomicon/) is for those who wish to dig deeper into `unsafe` rust and FFI.
9+
The 'nomicon is helpful for understanding how things like the `tskit` rust API can be built in the first place.
10+
11+
## Conventions used in this document
12+
13+
Here, `tskit` means the rust API.
14+
`tskit-c` and `tskit-python` refer to the C and Python APIs, respectively.
15+
16+
The phrase "data model" refers to [this](https://tskit.dev/tskit/docs/stable/data-model.html). This document will make little sense without an understanding of the data model.
17+
18+
## Relation to the C API
19+
20+
Where necessary, we will note differences from the behavior of `tskit-c`.
21+
22+
Much of the rust API works by calling the C API.
23+
We do not change the semantics of the C API.
24+
However, we do make stricter statements about the ownership relationships between types.
25+
For example, the C API can result in the following situation:
26+
27+
* A heap-allocated table collection is used to record data about the ancestry of a sample.
28+
* That table collection is used to initialize a tree sequence.
29+
The tree sequence is told to take ownership of the tables.
30+
31+
This is a case where the C API requires that you respectfully no longer work with the heap-allocated table collection. To do so is undefined behavior.
32+
33+
The rust API forbids such situations.
34+
The creation of a tree sequence from tables consumes the tables via a move operation.
35+
Thus, any further actions on the tables is a compiler error.
36+
37+
This example is the kinds of differences between `tskit` and `tskit-c`.
38+
Undefined behavior is (close to) impossible with `tskit`.
39+
40+
41+
## Quick overview
42+
43+
### Do you need `tskit-rust`?
444

545
The use-cases for `tskit-rust` are the same as for `tskit-c`:
646

747
1. Developing a new performance-oriented application.
848
2. The input/output of this application will be a `.trees` file.
949

10-
## What does `tskit-rust` add?
50+
### What does `tskit-rust` add?
1151

1252
Briefly, you get the performance of `C` and the strong safety guarantees of `rust`.
1353

14-
## What is `tskit-rust` missing?
54+
### What is `tskit-rust` missing?
1555

1656
The crate does not cover the entire `C` API.
1757
However, client code can make direct calls to that API via the module `tskit::bindings`.
1858

19-
## Adding `tskit` as a dependency to a rust project
59+
### Adding `tskit` as a dependency to a rust project
2060

2161
In your `Cargo.toml`:
2262

@@ -28,15 +68,8 @@ tskit = "~X.Y.Z"
2868
The latest version to fill in `X.Y.Z` can be found [here](https://crates.io/crates/tskit).
2969
See [here](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html) for how to specify version numbers.
3070

31-
### Feature flags.
71+
#### Feature flags.
3272

3373
`tskit` defines several [cargo features](https://doc.rust-lang.org/cargo/reference/features.html).
3474
These are defined in the [API docs](https://docs.rs/tskit/latest/tskit/#optional-features).
3575

36-
## Conventions used in this document
37-
38-
We assume a working knowledge of rust.
39-
Thus, we skip over the details of things like matching idioms, etc.,
40-
and just `.unwrap()`.
41-
42-
We also assume familiarity with the `tskit` [data model](https://tskit.dev/tskit/docs/stable/data-model.html).

0 commit comments

Comments
 (0)