magba/lib.rs
1/*
2 * Magba is licensed under The 3-Clause BSD, see LICENSE.
3 * Copyright 2025 Sira Pornsiriprasert <code@psira.me>
4 */
5
6#![cfg_attr(not(feature = "std"), no_std)]
7#![cfg_attr(docsrs, feature(doc_cfg))]
8
9/*!
10# Magba
11**Magba** is a performant analytical magnetic computation library for Rust.
12
13All physical quantities are assumed to be in SI units.
14Python bindings available via [PyMagba](https://github.com/p-sira/pymagba).
15
16## User Guide
17
18### Basic Features
19
20- [**Installing Magba** and controlling feature flags](https://github.com/p-sira/magba?tab=readme-ov-file#installation)
21- [Manipulating object **positions and orientations**](base::Transform#examples)
22- [Creating **magnets and computing fields**](magnets)
23- [**Using sensors** to measure magnetic fields](sensors)
24- [Grouping magnets and sensors into **collections**](collections)
25- [**Parallelization** using Rayon (enabled by default)](magnets#computing-b-field)
26
27### Advanced Features
28
29- [Calculating fields directly](fields)
30- [Using f32](base::Float)
31- [Unstable features](fields#internal-functions-unstable)
32
33## Acknowledgment
34
35Most of the field computation used in Magba is based on [MagpyLib](https://github.com/magpylib/magpylib).
36We would like to thank MagpyLib contributors for their hard work and contributions to the scientific community.
37*/
38
39#[cfg(feature = "alloc")]
40extern crate alloc;
41
42pub(crate) mod crate_utils;
43use crate::crate_utils::need_std;
44
45pub mod base;
46pub mod conversion;
47pub mod fields;
48pub mod measurement;
49
50pub mod currents;
51pub mod magnets;
52pub mod sensors;
53
54need_std!(
55 pub mod collections;
56
57 #[cfg(test)]
58 pub mod testing_util;
59);
60
61/// Re-exports of commonly used Magba structs, traits, and methods.
62pub mod prelude {
63 use super::*;
64
65 pub use base::{Float, Observer, SensorOutput, Source, Transform};
66 pub use currents::{CircularCurrent, Current};
67 pub use magnets::{CuboidMagnet, CylinderMagnet, Dipole, Magnet, SphereMagnet};
68 pub use sensors::{Sensor, hall_effect};
69
70 need_std!(
71 pub use collections::{
72 SourceComponent, SourceAssembly, ObserverComponent, ObserverAssembly, SourceArray,
73 ObserverArray,
74 };
75 );
76}