diff --git a/fern_sim/Cargo.toml b/fern_sim/Cargo.toml index 73e36a9..cc608ae 100644 --- a/fern_sim/Cargo.toml +++ b/fern_sim/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "fern_sim" version = "0.1.0" +edition = "2018" authors = ["You "] license = "MIT" homepage = "https://fernsim.example.com/" diff --git a/fern_sim/src/cells.rs b/fern_sim/src/cells.rs deleted file mode 100644 index 3697d5d..0000000 --- a/fern_sim/src/cells.rs +++ /dev/null @@ -1,12 +0,0 @@ -//! The simulation of biological cells, which is as low-level as we go. - -pub struct Cell { - x: f64, - y: f64 -} - -impl Cell { - pub fn distance_from_origin(&self) -> f64 { - f64::hypot(self.x, self.y) - } -} diff --git a/fern_sim/src/lib.rs b/fern_sim/src/lib.rs index ad94c18..1c51c66 100644 --- a/fern_sim/src/lib.rs +++ b/fern_sim/src/lib.rs @@ -1,7 +1,9 @@ //! Simulate the growth of ferns, from the level of //! individual cells on up. -pub mod cells; +#![warn(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + pub mod plant_structures; pub mod simulation; pub mod spores; diff --git a/fern_sim/src/plant_structures/leaves.rs b/fern_sim/src/plant_structures/leaves.rs index 50d63f5..dce330a 100644 --- a/fern_sim/src/plant_structures/leaves.rs +++ b/fern_sim/src/plant_structures/leaves.rs @@ -2,5 +2,5 @@ //! Simulation of individual leaves (for the formation of leaves, see `stem`). pub struct Leaf { - x: bool + pub x: bool } diff --git a/fern_sim/src/plant_structures/mod.rs b/fern_sim/src/plant_structures/mod.rs index 32ba8eb..723cc9b 100644 --- a/fern_sim/src/plant_structures/mod.rs +++ b/fern_sim/src/plant_structures/mod.rs @@ -43,3 +43,17 @@ impl Fern { self.stems.iter().all(|s| !s.furled) } } + +/// Create and return a [`VascularPath`] which represents the path of +/// nutrients from the given [`Root`][r] to the given [`Leaf`](leaves::Leaf). +/// +/// [r]: roots::Root +pub fn trace_path(leaf: &leaves::Leaf, root: &roots::Root) -> VascularPath { + VascularPath { from: leaf.x, to: root.x } +} + +#[doc(alias = "route")] +pub struct VascularPath { + pub from: bool, + pub to: bool, +} diff --git a/fern_sim/src/plant_structures/roots.rs b/fern_sim/src/plant_structures/roots.rs index d40b4f3..148f7b1 100644 --- a/fern_sim/src/plant_structures/roots.rs +++ b/fern_sim/src/plant_structures/roots.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] pub struct Root { - x: bool + pub x: bool } pub type RootSet = Vec; diff --git a/fern_sim/src/plant_structures/stems.rs b/fern_sim/src/plant_structures/stems.rs index 70a8123..c85e81c 100644 --- a/fern_sim/src/plant_structures/stems.rs +++ b/fern_sim/src/plant_structures/stems.rs @@ -3,6 +3,10 @@ //! the feathery leaf structure that's the most immediately recognizable //! property of ferns. +// in plant_structures/stems.rs +pub mod xylem; +pub mod phloem; + pub struct Stem { pub furled: bool } diff --git a/fern_sim/src/plant_structures/stems/phloem.rs b/fern_sim/src/plant_structures/stems/phloem.rs new file mode 100644 index 0000000..0ee6037 --- /dev/null +++ b/fern_sim/src/plant_structures/stems/phloem.rs @@ -0,0 +1,6 @@ +//! Structures for distributing the products of photosynthesis. + +/// Tissue for translocating sucrose and other photosynthesis products. +pub struct Phloem { + pub flow_rate: f32, +} diff --git a/fern_sim/src/plant_structures/stems/xylem.rs b/fern_sim/src/plant_structures/stems/xylem.rs new file mode 100644 index 0000000..3278326 --- /dev/null +++ b/fern_sim/src/plant_structures/stems/xylem.rs @@ -0,0 +1,6 @@ +//! Structures for bringing nutrients from roots up to other parts of the plant. + +/// Vascular tissue for transporting water and nutrients from the roots. +pub struct Xylem { + pub flow_rate: f32, +} diff --git a/fern_sim/src/simulation.rs b/fern_sim/src/simulation.rs index 9fb16b6..9c0c5f8 100644 --- a/fern_sim/src/simulation.rs +++ b/fern_sim/src/simulation.rs @@ -4,7 +4,7 @@ use std::fs::File; use std::time::Duration; -use plant_structures::{Fern, FernType}; +use crate::plant_structures::{Fern, FernType}; /// The simulated universe. pub struct Terrarium { diff --git a/fern_sim/src/spores.rs b/fern_sim/src/spores.rs index a6cfd91..5c51851 100644 --- a/fern_sim/src/spores.rs +++ b/fern_sim/src/spores.rs @@ -2,27 +2,46 @@ //! Fern reproduction. -use cells::Cell; +use cells::{Cell, Gene}; /// A cell made by an adult fern. It disperses on the wind as part of /// the fern life cycle. A spore grows into a prothallus -- a whole -/// separate organism, up to 5mm across -- which produces a zygote, -/// which becomes a new fern. (Plant sex is complicated.) +/// separate organism, up to 5mm across -- which produces the zygote +/// that grows into a new fern. (Plant sex is complicated.) pub struct Spore { - x: bool -} - -/// A compartment, usually on the bottom of a leaf, where spores form. -pub struct Sporangium { - x: bool + size: f64 } /// Simulate the production of a spore by meiosis. pub fn produce_spore(factory: &mut Sporangium) -> Spore { - Spore { x: false } + Spore { size: 1.0 } +} + +/// Extract the genes in a particular spore. +pub(crate) fn genes(spore: &Spore) -> Vec { + todo!() } /// Mix genes to prepare for meiosis (part of interphase). fn recombine(parent: &mut Cell) { + todo!() } +pub struct Sporangium; + +mod cells { + //! The simulation of biological cells, which is as low-level as we go. + + pub struct Cell { + x: f64, + y: f64 + } + + impl Cell { + pub fn distance_from_origin(&self) -> f64 { + f64::hypot(self.x, self.y) + } + } + + pub struct Gene; +} diff --git a/fern_sim/tests/unfurl.rs b/fern_sim/tests/unfurl.rs index c60f078..59adc10 100644 --- a/fern_sim/tests/unfurl.rs +++ b/fern_sim/tests/unfurl.rs @@ -1,6 +1,8 @@ // tests/unfurl.rs - Fiddleheads unfurl in sunlight -extern crate fern_sim; +#![warn(rust_2018_idioms)] +#![allow(elided_lifetimes_in_paths)] + use fern_sim::Terrarium; use std::time::Duration;