Crate tskit[][src]

Expand description

A rust interface to tskit.

This crate provides a mapping of the tskit C API to rust. The result is an interface similar to the tskit Python interface, but with all operations implemented using compiled code.


Interface to the C library


  • The types listed above handle all the memory management!
  • All array accesses are range-checked.
  • Object lifetimes are clear:
    • Creating a tree sequence moves/consumes a table collection.
    • Tree lifetimes are tied to that of the parent tree sequence.
    • Table objects (NodeTable, etc..) are only represented by non-owning, immutable types.


The prelude module contains definitions that are difficult/annoying to live without. In particuar, this module exports various traits that make it so that client code does not have to use them a la carte.

We recomment that client code import all symbols from this module:

use tskit::prelude::*;

The various documentation examples manually use each trait both in order to illustrate which traits are needed and to serve as doc tests.

Optional features

Some features are optional, and are activated by requesting them in your Cargo.toml file.

To add features to your Cargo.toml file:

tskit = {version = "0.2.0", features=["feature0", "feature1"]}

What is missing?

  • A lot of wrappers to the C functions.
  • Tree sequence statistics!


pub use bindings::TSK_NODE_IS_SAMPLE;
pub use bindings::tsk_flags_t;
pub use bindings::tsk_id_t;
pub use bindings::tsk_size_t;
pub use error::TskitError;


Low-level (“unsafe”) bindings to the C API.

Error handling

Define traits related to wrapping tskit stuff

Support for table row metadata

Export commonly-use types and traits

Optional module for table and tree sequence provenance tables.

“Other” tskit types live here.


Convenience macro to handle implementing crate::metadata::MetadataRoundtrip


An edge ID

An immutable view of an edge table.

Row of an EdgeTable

An individual ID

An immutable view of a individual table.

Row of a IndividualTable

A migration ID

An immutable view of a migration table.

Row of a MigrationTable

A mutation ID

An immutable view of site table.

Row of a MutationTable

A node ID

An immtable view of a node table.

Row of a NodeTable

A population ID

An immutable view of site table.

Row of a PopulationTable

A provenance ID

A site ID

An immutable view of site table.

Row of a SiteTable

Modify behavior of crate::TableCollection::clear.

A table collection.

Modify behavior of crate::TableCollection::equals.

Modify behavior of crate::TableCollection::dump.

Modify behavior of crate::TableCollection::sort.

A Tree.

Specify the behavior of iterating over [Tree] objects. See [TreeSequence::tree_iterator].

A tree sequence.


Specify the traversal order used by Tree::traverse_nodes.


Interface for returning lists of node ids from types implementing TableAccess.

Immutable access to tables.

Provide pointer access to underlying C types


C API major version

C API minor version

C API patch version

The C API version in MAJOR.MINOR.PATCH format

Version of the rust crate.

Type Definitions

Handles return codes from low-level tskit functions.