demo_vk/
lib.rs

1use std::ops::{Add, Div, Mul, Range, Sub};
2
3pub mod app;
4pub mod demo;
5pub mod graphics;
6
7pub fn map<T>(x: T, input_range: Range<T>, output_range: Range<T>) -> T
8where
9    T: Copy
10        + Sub<Output = T>
11        + Add<Output = T>
12        + Div<Output = T>
13        + Mul<Output = T>,
14{
15    let (u, v) = (input_range.start, input_range.end);
16    let (s, t) = (output_range.start, output_range.end);
17    let m = (s - t) / (u - v);
18    let b = (t * u - v * s) / (u - v);
19    x * m + b
20}
21
22/// Add context to an anyhow error which includes a formatted error message, the
23/// file path, and the line number.
24///
25/// # Usage
26///
27/// Given a method which returns an anyhow result:
28///
29/// my_method()
30///     .with_context(!trace("some error message {}", some_variable))?;
31#[macro_export]
32macro_rules! trace {
33    ($($arg:tt)*) => {{
34        || {
35            let res = format!("{}:{} - {}", file!(), line!(), format!($($arg)*));
36            res
37        }
38    }}
39}