pub trait RoutingTableExt: RoutingTable + Sealed {
// Provided method
fn modify(
&mut self,
prefix: IpNet,
modify: impl FnOnce(Option<&mut Self::Value>) -> RouteModification<Self::Value>,
) -> Option<Self::Value> { ... }
}Expand description
Automatic extension methods for implementors of RoutingTable.
Provided Methods§
Sourcefn modify(
&mut self,
prefix: IpNet,
modify: impl FnOnce(Option<&mut Self::Value>) -> RouteModification<Self::Value>,
) -> Option<Self::Value>
fn modify( &mut self, prefix: IpNet, modify: impl FnOnce(Option<&mut Self::Value>) -> RouteModification<Self::Value>, ) -> Option<Self::Value>
Modify the route at prefix using the modify closure.
The closure may return:
RouteModification::Insert: a route will be inserted with the provided value (or replaced if it already exists).RouteModification::Remove: the route will be removed (if it exists).RouteModification::Noop: the table will not be modified. The closure may modify the value stored in the route (if present).
If the route was replaced or removed, the return value contains the value that was previously stored.
Prefer to use insert or
remove if possible; this function is
intended as a more-efficient alternative to
lookup_prefix_exact-then-mutate.
§Examples
let mut table = SimpleTable::default();
let result = table.modify("0.0.0.0/0".parse().unwrap(), |node| {
assert_eq!(None, node);
RouteModification::Insert(4)
});
assert_eq!(None, result);
assert_eq!(Some(&4), table.lookup("1.2.3.4".parse().unwrap()));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".