winroute/lib.rs
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19//! # WinRoute
20//! This crate is a utilities of high level of interface for manipulating
21//! and observing Windows's routing table
22//!
23//! # Examples
24//! ## Manage routing table
25//! ```rust no_run
26//! use winroute::*;
27//! 
28//! let manager = RouteManager::new().unwrap();
29//! let new_route = Route::new("223.6.6.6".parse().unwrap(), 32).metric(1);
30//! // add route
31//! if let Err(e) = manager.add_route(&new_route) {
32//!     eprintln!("{e}");
33//! }
34//! // delete route
35//! if let Err(e) = manager.delete_route(&new_route) {
36//!     eprintln!("{e}");
37//! }
38//! ```
39//!
40//! ## Listen a table change event
41//! ```rust no_run
42//! use winroute::*;
43//! use std::sync::Arc;
44//! 
45//! fn main() -> std::io::Result<()> {
46//!     let manager = RouteManager::new()?;
47//!     let recvier = manager.subscribe_route_change();
48//!     let ma = Arc::new(manager);
49//!     let mb = ma.clone();
50//! 
51//!     // start a thread to driven event loop, also can use async task to run this
52//!     std::thread::spawn(move || loop {
53//!         ma.poll().unwrap();
54//!     });
55//! 
56//!     // create a new route
57//!     let new_route = Route::new("223.6.6.6".parse().unwrap(), 32);
58//!     // add route to system
59//!     mb.add_route(&new_route)?;
60//! 
61//!     loop {
62//!         // listeing on route change event
63//!         let event = recvier.recv().unwrap();
64//!         println!("{:?}", event);
65//!     }
66//! }
67//! ```
68
69mod manager;
70mod route;
71
72#[cfg(windows)]
73mod windows;
74
75pub use manager::RouteEvent;
76pub use manager::RouteManager;
77pub use route::Route;
78