1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use crateHandle;
use ;
/// A simple wrapper for property maps defined by functions (usually closures).
///
/// This wrapper only exists because we can't implement `PropMap` directly for
/// any `F` where `F: Fn(Handle) -> Target` due to coherence rules.
///
/// # Example
///
/// ```
/// use lox::{
/// Handle, VertexHandle,
/// map::{FnMap, PropMap},
/// };
///
/// fn foo(map: &impl PropMap<VertexHandle>) {}
///
///
/// // This property map returns 27 for all handles with an id smaller than 10.
/// let map = FnMap(|h: VertexHandle| {
/// if h.to_usize() < 10 {
/// Some(27)
/// } else {
/// None
/// }
/// });
/// foo(&map); // works
///
/// // This property map always returns 3 (you don't need to use the handle).
/// // However, in this case, you should usually use `ConstMap`.
/// foo(&FnMap(|_| Some(3))); // works
/// ```
;