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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#![doc = include_str!("../README.md")]

mod bibliography;
mod context;
mod coord;
mod ellipsoid;
mod grid;
mod inner_op;
mod math;
mod op;

// The bread-and-butter
pub use crate::context::Context;
pub use crate::context::Minimal;
pub use crate::context::Plain;
pub use crate::coord::Coord;
pub use crate::ellipsoid::Ellipsoid;
pub use crate::Direction::Fwd;
pub use crate::Direction::Inv;

/// The bread-and-butter, shrink-wrapped for external use
pub mod preamble {
    pub use crate::context::Context;
    pub use crate::grid::Grid;
    pub use crate::op::Op;
    pub use crate::op::OpHandle;
    pub use crate::Coord;
    pub use crate::Direction;
    pub use crate::Direction::Fwd;
    pub use crate::Direction::Inv;
    pub use crate::Ellipsoid;
    pub use crate::Error;
    pub use crate::Minimal;
    pub use crate::Plain;
}

/// Preamble for InnerOp modules (built-in or user defined)
pub mod inner_op_authoring {
    pub use crate::preamble::*;
    pub use log::error;
    pub use log::info;
    pub use log::trace;
    pub use log::warn;

    pub use crate::context::Context;
    pub use crate::inner_op::InnerOp;
    pub use crate::inner_op::OpConstructor;
    pub use crate::math::*;
    pub use crate::op::OpDescriptor;
    pub use crate::op::OpParameter;
    pub use crate::op::ParsedParameters;
    pub use crate::op::RawParameters;

    #[cfg(test)]
    pub use crate::some_basic_coordinates;
}

/// Preamble for crate-internal modules, and authoring of Context providers
pub mod internal {
    pub use crate::context::Context;
    pub use crate::context::BUILTIN_ADAPTORS;
    pub use crate::inner_op_authoring::*;
    pub use std::collections::BTreeMap;
    pub use std::collections::BTreeSet;
    pub use std::path::PathBuf;

    pub use uuid::Uuid;
}

use thiserror::Error;
/// The *Rust Geodesy* errror messaging enumeration. Badly needs reconsideration
#[derive(Error, Debug)]
pub enum Error {
    #[error("i/o error")]
    Io(#[from] std::io::Error),

    #[error("error: {0}")]
    General(&'static str),

    #[error("syntax error: {0}")]
    Syntax(String),

    #[error("{0}: {1}")]
    Operator(&'static str, &'static str),

    #[error("invalid header (expected {expected:?}, found {found:?})")]
    InvalidHeader { expected: String, found: String },
    #[error("{message:?} (expected {expected:?}, found {found:?})")]
    Unexpected {
        message: String,
        expected: String,
        found: String,
    },

    #[error("operator {0} not found{1}")]
    NotFound(String, String),

    #[error("recursion too deep for {0}, at {1}")]
    Recursion(String, String),

    #[error("attempt to invert a non-invertible item: {0}")]
    NonInvertible(String),

    #[error("missing required parameter {0}")]
    MissingParam(String),

    #[error("malformed value for parameter {0}: {1}")]
    BadParam(String, String),

    #[error("unknown error")]
    Unknown,
}

/// `Fwd`: Indicate that a two-way operator, function, or method,
/// should run in the *forward* direction.
/// `Inv`: Indicate that a two-way operator, function, or method,
/// should run in the *inverse* direction.
#[derive(Debug, PartialEq, Eq)]
pub enum Direction {
    Fwd,
    Inv,
}

#[cfg(test)]
pub fn some_basic_coordinates() -> [Coord; 2] {
    let copenhagen = Coord::raw(55., 12., 0., 0.);
    let stockholm = Coord::raw(59., 18., 0., 0.);
    [copenhagen, stockholm]
}

#[cfg(doc)]
pub use crate::bibliography::Bibliography;