osrm-binding 0.1.4

Low-level, unsafe FFI bindings to the OSRM C++ library.
docs.rs failed to build osrm-binding-0.1.4
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 OSRM core 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

πŸ› οΈ Usage

Initialization

let engine = OsrmEngine::new("/path/to/france-latest.osrm", Algorithm::MLD)
.expect("Failed to initialize OSRM engine");

Route Calculation

let request = RouteRequestBuilder::default()
.points(vec![
    Point { longitude: 2.3522, latitude: 48.8566 }, // Paris
    Point { longitude: 5.3698, latitude: 43.2965 }, // Marseille
    ])
.build()
.unwrap();

let result = engine.route(request).unwrap();
println!("{:?}", result.routes.first().unwrap());

Table (Distance/Duration Matrix)

let request = TableRequest {
    sources: vec![Point { longitude: 2.3522, latitude: 48.8566 }],
    destinations: vec![
        Point { longitude: 5.3698, latitude: 43.2965 },
        Point { longitude: 4.8357, latitude: 45.7640 },
    ],
};

let response = engine.table(request).unwrap();
println!("{:?}", response.durations);

Simple Route

    let result = engine.simple_route(
        Point { longitude: 2.3522, latitude: 48.8566 },
        Point { longitude: 5.3698, latitude: 43.2965 },
    ).unwrap();
    
    println!("Duration: {}s, Distance: {}m", result.durations, result.distance);

Trip API

    let request = TripRequest {
        points: vec![
        Point { longitude: 2.3522, latitude: 48.8566 },
        Point { longitude: 4.8357, latitude: 45.7640 },
        Point { longitude: 5.3698, latitude: 43.2965 },
        ],
    };
    
    let trip = engine.trip(request).unwrap();
    println!("{:?}", trip);

πŸ”¬ Tests

To run the tests:

export OSRM_TEST_DATA_PATH="/absolute/path/to/france-latest.osrm"
cargo test

Make sure your .osrm file is correctly prepared using osrm-extract and osrm-contract.

πŸ“– License

MIT

Note: This library assumes the user has a working osrm-c-api compiled and accessible. You must generate .osrm files yourself using osrm-extract and osrm-contract.

✨ Contribution

Feel free to open issues or PRs if you want to improve performance, add more OSRM API bindings, or enhance usability.


Made with ❀️ in Rust.