Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
osrm-binding
Rust bindings for OSRM (Open Source Routing Machine), providing an idiomatic and type-safe interface to access core OSRM functionalities (route, table, trip) from Rust.
π Features
- πΊοΈ Calculate routes, trips, and distance/duration tables using OSRM
- π¦ Fully written in Rust
- π‘ Simple and safe API for high-performance routing
- π§ͺ Includes integration tests for route and table APIs
π¦ Installation
Add the crate to your Cargo.toml:
cargo add osrm-binding
Building Dependencies
This library requires OSRM to be built and linked. Below are instructions for setting up the dependencies.
Local Installation (Ubuntu 24.04)
Install the required system dependencies:
sudo apt update
sudo apt install build-essential git cmake pkg-config \
libbz2-dev libxml2-dev libzip-dev libboost-all-dev \
lua5.2 liblua5.2-dev libtbb-dev libfmt-dev
Dockerfile
Use the following Dockerfile to build your application in a containerized environment:
FROM rust:1.88.0-bookworm AS builder
WORKDIR /usr/src/app
COPY Cargo.toml Cargo.lock ./
COPY ./src ./src
RUN apt-get update && \
apt-get -y --no-install-recommends --no-install-suggests install \
ca-certificates \
cmake \
g++ \
gcc \
git \
libboost1.81-all-dev \
libbz2-dev \
liblua5.4-dev \
libtbb-dev \
libxml2-dev \
libzip-dev \
lua5.4 \
make \
pkg-config \
libfmt-dev
RUN ls -la /usr/lib/x86_64-linux-gnu/libboost_thread*
RUN cargo build --release -vv
FROM debian:bookworm-slim
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/target/release/my-bin ./
RUN apt-get update && \
apt-get install -y --no-install-recommends --no-install-suggests \
expat \
libboost-date-time1.81.0 \
libboost-iostreams1.81.0 \
libboost-program-options1.81.0 \
libboost-thread1.81.0 \
liblua5.4-0 \
libtbb12 && \
rm -rf /var/lib/apt/lists/* && \
ldconfig /usr/local/lib
CMD ["./my-bin"]
Note: Replace
my-binwith your actual binary name. This Dockerfile installs OSRM build dependencies and runtime libraries.
π οΈ Usage
Initialization
Initialize the OSRM engine with a preprocessed OSRM data file (e.g., generated via osrm-extract and osrm-contract):
use ;
let engine = new
.expect;
Route Calculation
Build and execute a route request:
use ;
let request = default
.points
.build
.unwrap;
let result = engine.route.unwrap;
println!;
Table (Distance/Duration Matrix)
Compute a distance/duration table:
use ;
let request = TableRequest ;
let response = engine.table.unwrap;
println!;
Simple Route
For quick single-origin to single-destination routing:
use Point;
let result = engine.simple_route.unwrap;
println!;
Trip API
Optimize a trip with multiple waypoints:
use ;
let request = TripRequest ;
let trip = engine.trip.unwrap;
println!;
π¬ Tests
To run the tests, set the environment variable for your OSRM data file and execute:
export OSRM_TEST_DATA_PATH="/absolute/path/to/france-latest.osrm"
cargo test
Ensure your .osrm file is prepared using osrm-extract and osrm-contract.
π Performance
Native performance using cargo bench
calculate_multiple_routes_around_paris_10km_mld
time: [5.4872 ms 5.6545 ms 5.8246 ms]
calculate_multiple_routes_around_paris_100km_mld
time: [13.063 ms 13.877 ms 14.652 ms]
Found 2 outliers among 100 measurements (2.00%)
2 (2.00%) low mild
calculate_multiple_routes_around_paris_10km_ch
time: [3.8034 ms 3.8599 ms 3.9175 ms]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild
calculate_multiple_routes_around_paris_100km_ch
time: [5.9891 ms 6.2444 ms 6.4946 ms]
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) low mild
π License
This project is licensed under the MIT License.
β¨ Contributions
Contributions are welcome! Feel free to open issues or pull requests to improve performance, add more OSRM API bindings, or enhance usability.
Made with β€οΈ in Rust.