Skip to main content

ForwardGraph

Struct ForwardGraph 

Source
pub struct ForwardGraph { /* private fields */ }
Expand description

Forward-time representation of a demes::Graph.

Implementations§

Source§

impl ForwardGraph

Source

pub fn new_discrete_time<F: Into<ForwardTime> + Debug + Copy>( graph: Graph, burnin_time: F, ) -> Result<Self, DemesForwardError>

Constructor

§Parameters
  • graph: a demes::Graph.
  • burnin_time: Burn-in time for the model.
Examples found in repository?
examples/iterate_gutenkunst.rs (line 45)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn update_state<F: Into<ForwardTime> + Debug + Copy>( &mut self, parental_generation_time: F, ) -> Result<(), DemesForwardError>

Update the internal state of the graph to the parental generation time parental_generation_time.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 51)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn num_demes_in_model(&self) -> usize

The total number of demes in the graph.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 71)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn ancestry_proportions(&self, offspring_deme: usize) -> Option<&[f64]>

The ancestry proporitions for a given offspring deme at the current time.

§Parameters
  • offspring_deme: the index of an offspring deme.
§Returns
  • Some(&[f64]) if offspring_deme is a valid index and extant offspring demes exist.
  • None otherwise.
Examples found in repository?
examples/iterate_gutenkunst.rs (line 97)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn cloning_rates(&self) -> Option<&[CloningRate]>

Get cloning rates of all offspring demes.

Returns None if there are no extant offspring demes.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 86)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn selfing_rates(&self) -> Option<&[SelfingRate]>

Get selfing rates of all offspring demes.

Returns None if there are no extant offspring demes.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 83)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn last_time_updated(&self) -> Option<ForwardTime>

Obtain the time corresponding to the last call of ForwardGraph::update_state.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 132)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn end_time(&self) -> ForwardTime

Obtain the end time of the model.

Source

pub fn time_iterator(&self) -> impl Iterator<Item = ForwardTime>

Return an iterator over time values.

The iterator starts at the last updated time and continues until the end time.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 53)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn parental_deme_sizes(&self) -> Option<&[CurrentSize]>

Obtain the sizes of each parental deme.

The length of the slice is equal to the number of demes in the graph (see ForwardGraph::num_demes_in_model).

Returns None if there are no parental demes at the current time.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 64)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn offspring_deme_sizes(&self) -> Option<&[CurrentSize]>

Obtain the sizes of each offspring deme.

The length of the slice is equal to the number of demes in the graph (see ForwardGraph::num_demes_in_model).

Returns None if there are no offspring demes at the current time.

Examples found in repository?
examples/iterate_gutenkunst.rs (line 59)
25fn iterate_model(
26    graph: demes::Graph,
27    burnin: i32,
28) -> Result<demes_forward::ForwardTime, Box<dyn std::error::Error>> {
29    // Convert the backwards time model
30    // to a forward-time representation with
31    // some generations of burn-in.
32    //
33    // The forward graph is mutable because
34    // we will update its internal state
35    // during iteration.
36    //
37    // The final argument, None, means to apply
38    // no rounding when converting times into generations.
39    // None is safe for this model, but may not be so generally.
40    // See the demes-rs docs at https://docs.rs/demes for details on rounding methods.
41    //
42    // NOTE: the implementation of rounding in demes is currently an enum.
43    // In the future, it may become a trait, which would break API here
44    // but allow for more flexibility in client code.
45    let mut forward_graph = demes_forward::ForwardGraph::new_discrete_time(graph, burnin)?;
46
47    // Update the internal model state
48    // to parental generation 0, meaning
49    // that the first offspring will have
50    // birth times of generation 1.
51    forward_graph.update_state(0)?;
52
53    for time in forward_graph.time_iterator() {
54        // time refers to a parental generation.
55        // Therefore, when we have iterated to the time point
56        // where the final generation are now parents, there
57        // are no offspring and forward_graph.offspring_deme_sizes()
58        // returns None.
59        if let Some(offspring_deme_sizes) = forward_graph.offspring_deme_sizes() {
60            // Get the parent deme sizes.
61            // Given our previous "if let ...", this statement cannot/should not
62            // return None, and we will panic! if it does.
63            let parental_deme_sizes = forward_graph
64                .parental_deme_sizes()
65                .unwrap_or_else(|| panic!("expected parental deme sizes at time {time}"));
66
67            // The deme size slices have lengths equal to the total
68            // number of demes in the graph.
69            assert_eq!(
70                offspring_deme_sizes.len(),
71                forward_graph.num_demes_in_model()
72            );
73            assert_eq!(
74                parental_deme_sizes.len(),
75                forward_graph.num_demes_in_model()
76            );
77
78            // Get the selfing and cloning rates for each deme.
79            // The order is the same as the order of demes in the graph.
80            // This model has no selfing/cloning, but we include the accesses
81            // for completeness.
82            let selfing_rates = forward_graph
83                .selfing_rates()
84                .unwrap_or_else(|| panic!("expected selfing rates"));
85            let cloning_rates = forward_graph
86                .cloning_rates()
87                .unwrap_or_else(|| panic!("expected cloning rates"));
88
89            assert_eq!(selfing_rates.len(), forward_graph.num_demes_in_model());
90            assert_eq!(cloning_rates.len(), forward_graph.num_demes_in_model());
91
92            // Iterate over offspring deme indexes
93            for (offspring_deme_index, offspring_deme_size) in
94                offspring_deme_sizes.iter().enumerate()
95            {
96                let ancestry_proportions = forward_graph
97                    .ancestry_proportions(offspring_deme_index)
98                    .unwrap_or_else(|| {
99                        panic!(
100                            "expected ancestry proportions for offspring deme {offspring_deme_index} at time {time}",
101                        )
102                    });
103                if offspring_deme_size > &0.0 {
104                    // If an the offspring deme is extant (size > 0),
105                    // then any ancestral deme with a proportion > 0 must
106                    // have size > 0.
107                    // Further, the sum of all ancestry proportions into
108                    // the offspring deme must sum to ~1.0.
109                    assert!((ancestry_proportions.iter().sum::<f64>() - 1.0).abs() <= f64::EPSILON);
110                    for (ancestor, proportion) in ancestry_proportions.iter().enumerate() {
111                        if proportion > &0.0 {
112                            assert!(parental_deme_sizes[ancestor] > 0.0);
113                        }
114                        // NOTE: is incorrect to assert that the ancestor
115                        // size is 0 if the ancestry proportion of that ancestor
116                        // into offspring_deme is 0!
117                        // The ancestor deme could exist but only as an ancestor
118                        // of another offspring deme in the graph.
119                    }
120                } else {
121                    // An offspring deme with size 0 has no ancestry.
122                    assert_eq!(ancestry_proportions.iter().sum::<f64>(), 0.0);
123                }
124            }
125        }
126
127        // Update the internal state to the next time point.
128        forward_graph.update_state(time + 1.into())?;
129    }
130
131    Ok(forward_graph
132        .last_time_updated()
133        .expect("expected Some(ForwardTime)"))
134}
Source

pub fn any_extant_parental_demes(&self) -> bool

Return true if there are any extant parental demes at the current time.

Source

pub fn any_extant_offspring_demes(&self) -> bool

Return true if there are any extant offspring demes at the current time.

Source

pub fn num_extant_parental_demes(&self) -> usize

Return the number of extant parental demes at the current time.

Source

pub fn num_extant_offspring_demes(&self) -> usize

Return the number of extant offspring demes at the current time.

Source

pub fn size_at<'a, I: Into<DemeId<'a>>, T: Into<BackwardTimeWrapper>>( &self, deme: I, time: T, ) -> Result<Option<CurrentSize>, DemesForwardError>

Obtain the size (number of parental individuals) of a given deme at a given time.

§Parameters
  • deme: a deme identifier
  • time: a time
§Returns
  • Some(DemeSize) if there are parents at the given time.
  • None if deme does not exist or the deme exists but is not in existence at time.
§Errors

DemesForwardError if the calculation of deme size returns an invalid demes::DemeSize or if time is not a valid value.

§Notes
  • Time is measured backwards in time from 0.0 (inclusive of zero). The reason is that it is usually easier to reason about time in this way.
  • Unlike a demes::Graph, time does not go back in the past to “infinity”. The first parental generation is considered to exist at a time one generation prior to the start of events in the graph plus the burn-in time.
Source

pub fn deme_size_history<'a, I>( &self, deme: I, ) -> Result<impl Iterator<Item = DemeSizeAt>, DemesForwardError>
where I: Debug + Into<DemeId<'a>>,

Generate an iterator over the size history of a deme.

§Parameters
  • deme: the index or name of the deme
§Returns

An iterator over instances of DemeSizeAt.

§Errors

This function will return an error if:

  • deme does not exist in the graph
§Note

The iterated values are lazily evaluated. First self is cloned. Then, the entire model history is iterated over, and the output data is returned during iteration.

§Panics
  • Cloning the graph requires allocations which will panic if the system runs out of memory
Source

pub fn backwards_start_time(&self) -> Time

Return the time in the past when the first generation of the model exists. This time point represents the individuals alive at time zero (forwards in time) who are the ancestors of those individuals born at time 1 of the model.

Source

pub fn backwards_burn_in_time(&self) -> Time

Return the time in the model at the end of any “burn-in”.

§Note

This value is distinct from the burn-in duration. Instead, this value represents the time when all alive individuals are the ancestors of the first finite time in the demes::Graph.

Source

pub fn time_to_backward<T: Into<ForwardTimeWrapper>>( &self, time: T, ) -> Result<Option<Time>, DemesForwardError>

Convert a forward time value (ForwardTime) into a backwards time value (demes::Time)

§Returns
  • None if time is ancestral to the start of the model or more recent than the model’s end.
Source

pub fn time_to_forward<T: Into<BackwardTimeWrapper>>( &self, time: T, ) -> Result<Option<ForwardTime>, DemesForwardError>

Convert a backwards time value (demes::Time) into a forward time value (ForwardTime)

§Returns
  • None if time is ancestral to the start of the model or more recent than the model’s end.
Source

pub fn deme_names(&self) -> Box<[&str]>

Get the names of each deme in the model.

§Note

Implemented by calling demes::Graph::deme_names.

Source

pub fn demes_graph(&self) -> &Graph

Access to the underlying demes::Graph

Trait Implementations§

Source§

impl Clone for ForwardGraph

Source§

fn clone(&self) -> ForwardGraph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ForwardGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.