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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0
//! Graph conversion traits and utilities
//!
//! This module provides traits and functions for converting between different graph representations.
use crate;
/// Trait for graph types that can be constructed from other graph types
///
/// This trait provides a standardized way to convert from any source graph
/// to the implementing graph type. It handles the common pattern of copying
/// nodes and edges from a source graph while managing capacity constraints
/// and error handling.
///
/// # Type Parameters
/// * `NI` - The node index type for the target graph
/// * `E` - The error type returned by the conversion
///
/// # Implementation Guidelines
///
/// Implementations should:
/// 1. Iterate over all nodes in the source graph and copy them
/// 2. Iterate over all edges in the source graph and copy them
/// 3. Handle capacity constraints appropriately for the target graph type
/// 4. Convert source graph errors to the target error type
/// 5. Support empty graphs (graphs with no nodes/edges)
///
/// # Examples
///
/// ```
/// use heapless_graphs::conversions::FromGraph;
/// use heapless_graphs::matrix::simple_matrix::Matrix;
/// use heapless_graphs::adjacency_list::map_adjacency_list::MapAdjacencyList;
/// // ... (setup source graph)
/// // let target_matrix = Matrix::from_graph(&source_graph)?;
/// ```