pub struct MaterialDatabase { /* private fields */ }Expand description
An in-memory database of material entries.
Implementations§
Source§impl MaterialDatabase
impl MaterialDatabase
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a database pre-populated with common engineering materials.
Includes: steel 1020, aluminium 6061, copper, titanium Ti-6Al-4V, PTFE, water (liquid, 20 °C), and dry air (20 °C, 1 atm).
Sourcepub fn add_material(&mut self, entry: MaterialEntry)
pub fn add_material(&mut self, entry: MaterialEntry)
Add a material to the database.
Sourcepub fn get_material(&self, name: &str) -> Option<&MaterialEntry>
pub fn get_material(&self, name: &str) -> Option<&MaterialEntry>
Look up a material by name (case-sensitive).
Returns Some(&MaterialEntry) if found, None otherwise.
Sourcepub fn remove_material(&mut self, name: &str) -> bool
pub fn remove_material(&mut self, name: &str) -> bool
Remove a material by name.
Returns true if a material was removed, false if not found.
Sourcepub fn search_by_density(
&self,
min_density: f64,
max_density: f64,
) -> Vec<&MaterialEntry>
pub fn search_by_density( &self, min_density: f64, max_density: f64, ) -> Vec<&MaterialEntry>
Return all materials whose density falls within [min_density, max_density].
Sourcepub fn search_by_youngs_modulus(
&self,
min_e: f64,
max_e: f64,
) -> Vec<&MaterialEntry>
pub fn search_by_youngs_modulus( &self, min_e: f64, max_e: f64, ) -> Vec<&MaterialEntry>
Return all materials whose Young’s modulus falls within [min_e, max_e].
Sourcepub fn export_json(&self) -> String
pub fn export_json(&self) -> String
Serialise the entire database to a JSON string.
The format is a JSON array of objects: [{"name":..., ...}, ...].
Sourcepub fn import_json(json: &str) -> Result<Self, String>
pub fn import_json(json: &str) -> Result<Self, String>
Deserialise a database from a JSON string produced by export_json.
Returns Err if parsing fails. This is a minimal hand-rolled parser that
handles the exact format produced by export_json.
Trait Implementations§
Source§impl Debug for MaterialDatabase
impl Debug for MaterialDatabase
Source§impl Default for MaterialDatabase
impl Default for MaterialDatabase
Source§fn default() -> MaterialDatabase
fn default() -> MaterialDatabase
Auto Trait Implementations§
impl Freeze for MaterialDatabase
impl RefUnwindSafe for MaterialDatabase
impl Send for MaterialDatabase
impl Sync for MaterialDatabase
impl Unpin for MaterialDatabase
impl UnsafeUnpin for MaterialDatabase
impl UnwindSafe for MaterialDatabase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.