### Calculate Kundli with Default Engine (Rust) Source: https://docs.rs/kundli-rs/latest/index.html Demonstrates the quick start usage of the kundli-rs crate to calculate a kundli. It involves creating an `AstroRequest` and `KundliConfig`, then calling `calculate_kundli`. Dependencies include the `kundli_rs` crate itself. ```rust use kundli_rs::calculate_kundli; use kundli_rs::kundli::astro::{AstroBody, AstroRequest}; use kundli_rs::kundli::config::KundliConfig; let request = AstroRequest::new( 2451545.0, 37.5665, 126.9780, vec![AstroBody::Sun, AstroBody::Moon, AstroBody::Saturn], ); let config = KundliConfig::from_request(&request) .with_include_d9(true) .with_include_dasha(true); let result = calculate_kundli(request, config)?; println!("Lagna sign: {:?}", result.lagna.sign); ``` -------------------------------- ### Pada Constants and Constructor in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.Pada.html Provides constants for the minimum (1) and maximum (4) valid pada values, along with a constructor function `new` that creates a checked Pada value, returning an Option. The `get` method retrieves the raw one-based pada value. ```rust pub const MIN: u8 = 1 pub const MAX: u8 = 4 pub fn new(value: u8) -> Option pub const fn get(self) -> u8 ``` -------------------------------- ### Pada Constants and Constructor in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.Pada.html?search=u32+-%3E+bool Provides constants for the minimum (1) and maximum (4) valid pada values, along with a constructor function `new` that creates a checked `Pada` value. The `get` method returns the raw one-based pada value. ```rust pub const MIN: u8 = 1; pub const MAX: u8 = 4; pub fn new(value: u8) -> Option; pub const fn get(self) -> u8; ``` -------------------------------- ### Initialize and Use SwissEphAstroEngine Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphAstroEngine.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the instantiation of the SwissEphAstroEngine using a configuration object and the execution of astronomical calculations via the AstroEngine trait. ```rust use kundli_rs::kundli::astro::{SwissEphAstroEngine, SwissEphConfig, AstroEngine, AstroRequest}; // Initialize the engine with a configuration let config = SwissEphConfig::default(); let engine = SwissEphAstroEngine::new(config); // Perform a calculation let request = AstroRequest::default(); let result = engine.calculate(&request); ``` -------------------------------- ### Test Degrees in Nakshatra Calculation in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search=u32+-%3E+bool Tests the `degrees_in_nakshatra` function, which calculates the remaining degrees within the current Nakshatra. It checks basic cases, including the start of a Nakshatra (0 degrees) and a value within a Nakshatra. It also tests the boundary condition where the input longitude is exactly the start of the next Nakshatra, expecting 0 degrees remaining. ```rust #[test] fn test_degrees_in_nakshatra_basic() { assert!((degrees_in_nakshatra(0.0).unwrap() - 0.0).abs() < 1e-10); assert!((degrees_in_nakshatra(6.666).unwrap() - 6.666).abs() < 1e-3); } #[test] fn test_degrees_in_nakshatra_across_boundary() { let result = degrees_in_nakshatra(DEGREES_PER_NAKSHATRA).unwrap(); assert!(result.abs() < 1e-10); } #[test] fn test_degrees_in_nakshatra_invalid() { assert!(degrees_in_nakshatra(f64::NAN).is_err()); assert!(degrees_in_nakshatra(f64::INFINITY).is_err()); } ``` -------------------------------- ### Get Mahadasha Duration in Years (Rust) Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/dasha.rs.html?search= Returns the standard duration in years for each Dasha Lord in the Vimshottari system. Uses a match statement to map each DashaLord enum variant to its corresponding year count. ```Rust fn mahadasha_years(lord: DashaLord) -> f64 { match lord { DashaLord::Ketu => 7.0, DashaLord::Venus => 20.0, DashaLord::Sun => 6.0, DashaLord::Moon => 10.0, DashaLord::Mars => 7.0, DashaLord::Rahu => 18.0, DashaLord::Jupiter => 16.0, DashaLord::Saturn => 19.0, DashaLord::Mercury => 17.0, } } ``` -------------------------------- ### Initialize and Configure SwissEphConfig Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html Demonstrates how to instantiate a new SwissEphConfig object and set the required ephemeris path for the astronomical engine. ```rust use kundli_rs::kundli::astro::SwissEphConfig; // Create a new configuration let config = SwissEphConfig::new(); // Set the ephemeris path let configured = config.with_ephemeris_path("/path/to/ephemeris"); ``` -------------------------------- ### Test degrees_in_sign functionality Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/sign.rs.html?search=std%3A%3Avec Verifies the calculation of degrees relative to the start of a zodiac sign. It ensures correct normalization across sign boundaries and handles negative inputs and invalid floating-point values. ```rust #[test] fn test_degrees_in_sign_basic() { assert!((degrees_in_sign(0.0).unwrap() - 0.0).abs() < 1e-10); assert!((degrees_in_sign(15.0).unwrap() - 15.0).abs() < 1e-10); assert!((degrees_in_sign(29.999).unwrap() - 29.999).abs() < 1e-10); } #[test] fn test_degrees_in_sign_across_boundary() { assert!((degrees_in_sign(30.0).unwrap() - 0.0).abs() < 1e-10); assert!((degrees_in_sign(45.5).unwrap() - 15.5).abs() < 1e-10); assert!((degrees_in_sign(90.0).unwrap() - 0.0).abs() < 1e-10); } ``` -------------------------------- ### Initialize and Configure SwissEphConfig Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html?search=std%3A%3Avec Demonstrates how to instantiate a new SwissEphConfig object and set the required ephemeris path for the astronomical engine. ```rust use kundli_rs::kundli::astro::SwissEphConfig; let config = SwissEphConfig::new() .with_ephemeris_path("/path/to/ephemeris"); ``` -------------------------------- ### Define DashaPeriod Struct in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.DashaPeriod.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Defines the DashaPeriod struct, representing a single mahadasha period. It includes fields for the Mahadasha lord and the start and end Julian days in Universal Time. ```rust pub struct DashaPeriod { pub lord: DashaLord, pub start_jd_ut: f64, pub end_jd_ut: f64, } ``` -------------------------------- ### Initialize and Use SwissEphAstroEngine Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphAstroEngine.html?search=std%3A%3Avec Demonstrates the definition of the SwissEphAstroEngine struct and the method signature for creating a new instance. It also shows the interface for calculating astronomical data using the AstroEngine trait. ```rust pub struct SwissEphAstroEngine { /* private fields */ } impl SwissEphAstroEngine { pub fn new(config: SwissEphConfig) -> Self { // Implementation logic } } impl AstroEngine for SwissEphAstroEngine { fn calculate(&self, request: &AstroRequest) -> Result { // Calculation logic } } ``` -------------------------------- ### Create SwissEphAstroEngine Instance (Rust) Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphAstroEngine.html?search= Provides a constructor function `new` for the SwissEphAstroEngine. This function takes a `SwissEphConfig` as input and returns a new instance of the engine, configured according to the provided settings. ```rust pub fn new(config: SwissEphConfig) -> Self ``` -------------------------------- ### Configure SwissEphAstroEngine in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/astro/engine.rs.html Demonstrates the builder pattern used to configure the SwissEphAstroEngine, allowing users to specify paths for ephemeris data files. ```rust let config = SwissEphConfig::new().with_ephemeris_path("/path/to/ephemeris"); let engine = SwissEphAstroEngine::new(config); ``` -------------------------------- ### Rust Struct for Dasha Period Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/model.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Represents a single mahadasha period within the Vimshottari system. It stores the `lord` of the dasha, and the inclusive start and end Julian days in Universal Time. ```rust pub struct DashaPeriod { /// Mahadasha lord. pub lord: DashaLord, /// Inclusive start Julian day in Universal Time. pub start_jd_ut: f64, /// End Julian day in Universal Time. pub end_jd_ut: f64, } ``` -------------------------------- ### Create SwissEphConfig Instance in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to create and configure instances of SwissEphConfig. The `new` function creates an empty configuration, while `with_ephemeris_path` allows setting the ephemeris file location. ```rust pub fn new() -> Self ``` ```rust pub fn with_ephemeris_path(self, ephemeris_path: impl Into) -> Self ``` -------------------------------- ### Test Nakshatra Progress and Degree Normalization Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search= Validates the calculation of progress ratios within a Nakshatra and ensures degree normalization across boundaries. These tests confirm that ratios reset correctly at the start of each Nakshatra segment. ```rust #[test] fn test_nakshatra_progress_ratio_middle() { let mid_degrees = DEGREES_PER_NAKSHATRA / 2.0; let ratio = nakshatra_progress_ratio(mid_degrees).unwrap(); assert!((ratio - 0.5).abs() < 1e-10); } #[test] fn test_degrees_in_nakshatra_across_boundary() { let result = degrees_in_nakshatra(DEGREES_PER_NAKSHATRA).unwrap(); assert!(result.abs() < 1e-10); } ``` -------------------------------- ### Create Empty SwissEphConfig (Rust) Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html?search= Provides a constructor function `new` for SwissEphConfig. This function creates an empty configuration object, which can then be further customized using other methods. ```rust pub fn new() -> Self ``` -------------------------------- ### HouseNumber Constants and Constructor in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.HouseNumber.html Provides constants `MIN` and `MAX` for the valid range of `HouseNumber` (1 and 12 respectively). Includes a `new` function to create a checked `HouseNumber` and a `get` function to retrieve its raw value. ```rust pub const MIN: u8 = 1; pub const MAX: u8 = 12; pub fn new(value: u8) -> Option; pub const fn get(self) -> u8; ``` -------------------------------- ### Initialize KundliConfig Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/config/struct.KundliConfig.html?search=std%3A%3Avec Methods for creating a new configuration instance. Users can either specify all parameters manually or derive them from an existing AstroRequest object. ```rust impl KundliConfig { pub fn new(zodiac: ZodiacType, ayanamsha: Ayanamsha, house_system: HouseSystem, node_type: NodeType) -> Self { ... } pub fn from_request(request: &AstroRequest) -> Self { ... } } ``` -------------------------------- ### Derive Vimshottari Dasha periods in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/dasha.rs.html?search=std%3A%3Avec Calculates the sequence of Vimshottari Dasha periods using astronomical input. It validates the sidereal zodiac requirement and computes the start and end Julian dates for each mahadasha lord. ```rust pub(crate) fn derive_vimshottari_dasha_from_input( input: &KundliDeriveInput, ) -> Result { if input.meta.zodiac != crate::kundli::astro::ZodiacType::Sidereal { return Err(DeriveError::UnsupportedZodiac(input.meta.zodiac)); } let moon = input .body(AstroBody::Moon) .ok_or(DeriveError::MissingMoon)?; let current_lord = dasha_lord_for_nakshatra(moon.nakshatra.nakshatra); let current_duration_days = mahadasha_duration_days(current_lord); let current_start_jd_ut = input.meta.jd_ut - current_duration_days * moon.nakshatra_progress_ratio; let sequence_start = DashaLord::SEQUENCE .iter() .position(|&lord| lord == current_lord) .expect("current dasha lord must be part of the Vimshottari sequence"); let mut next_start_jd_ut = current_start_jd_ut; let mut mahadashas = Vec::with_capacity(DashaLord::SEQUENCE.len()); for offset in 0..DashaLord::SEQUENCE.len() { let lord = DashaLord::SEQUENCE[(sequence_start + offset) % DashaLord::SEQUENCE.len()]; let end_jd_ut = next_start_jd_ut + mahadasha_duration_days(lord); mahadashas.push(DashaPeriod { lord, start_jd_ut: next_start_jd_ut, end_jd_ut, }); next_start_jd_ut = end_jd_ut; } Ok(VimshottariDasha { moon_nakshatra: moon.nakshatra.nakshatra, current_mahadasha: mahadashas[0].clone(), mahadashas, }) } ``` -------------------------------- ### SwissEphConfig Implementations Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html?search=std%3A%3Avec Details on the implementations for the SwissEphConfig struct, including Clone, Debug, Default, PartialEq, and Eq. ```APIDOC ## Implementations for SwissEphConfig ### `impl Clone for SwissEphConfig` Provides methods for cloning `SwissEphConfig` instances. #### `clone()` Returns a duplicate of the value. - **Method**: `clone` - **Returns**: `SwissEphConfig` #### `clone_from(source: &Self)` Performs copy-assignment from `source`. - **Method**: `clone_from` - **Parameters**: - **source** (`&Self`) - The source `SwissEphConfig` to copy from. ### `impl Debug for SwissEphConfig` Provides debugging capabilities for `SwissEphConfig`. #### `fmt(f: &mut Formatter<'_>)` Formats the value using the given formatter. - **Method**: `fmt` - **Parameters**: - **f** (`&mut Formatter<'_>`) - The formatter to use. - **Returns**: `Result` ### `impl Default for SwissEphConfig` Provides a default value for `SwissEphConfig`. #### `default()` Returns the “default value” for a type. - **Method**: `default` - **Returns**: `SwissEphConfig` ### `impl PartialEq for SwissEphConfig` Provides equality comparison for `SwissEphConfig`. #### `eq(other: &SwissEphConfig)` Tests for `self` and `other` values to be equal. - **Method**: `eq` - **Parameters**: - **other** (`&SwissEphConfig`) - The other `SwissEphConfig` to compare with. - **Returns**: `bool` #### `ne(other: &Rhs)` Tests for `!=`. - **Method**: `ne` - **Parameters**: - **other** (`&Rhs`) - The other value to compare with. - **Returns**: `bool` ### `impl Eq for SwissEphConfig` Marks `SwissEphConfig` as having a total equivalence relation. ### `impl StructuralPartialEq for SwissEphConfig` Provides structural partial equality comparison. ``` -------------------------------- ### Get Nakshatra Placement from Longitude - Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search= Returns the full nakshatra placement, including nakshatra, pada, and degrees within the nakshatra. This is a convenience function that combines individual derivations. Returns an error if the input longitude is not finite. ```Rust pub(crate) fn nakshatra_placement_from_longitude( longitude: f64, ) -> Result { let normalized = normalize_longitude(longitude)?; let nakshatra = nakshatra_from_longitude(normalized)?; let pada = pada_from_longitude(normalized)?; let degrees = degrees_in_nakshatra(normalized)?; Ok(NakshatraPlacement { nakshatra, pada, degrees_in_nakshatra: degrees, }) } ``` -------------------------------- ### Map Nakshatra to Dasha Lord - Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search= Returns the ruling dasha lord for a given nakshatra. In Vimshottari dasha, each nakshatra is ruled by one of the 9 planets, with the sequence starting at Ketu (Ashwini) and cycling every 9 nakshatras. ```Rust pub(crate) fn dasha_lord_for_nakshatra(nakshatra: Nakshatra) -> DashaLord { let nakshatra_index = nakshatra_to_index(nakshatra); let lord_index = nakshatra_index % 9; DashaLord::SEQUENCE[lord_index] } ``` -------------------------------- ### Derive Vimshottari Dasha periods in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/dasha.rs.html?search=u32+-%3E+bool Calculates the Vimshottari Dasha sequence for a given astrological result. It requires sidereal zodiac input and the presence of the Moon to determine the starting dasha lord and subsequent time periods. ```rust pub fn derive_vimshottari_dasha(astro: &AstroResult) -> Result { let input = KundliDeriveInput::from_astro(astro)?; derive_vimshottari_dasha_from_input(&input) } fn mahadasha_duration_days(lord: DashaLord) -> f64 { mahadasha_years(lord) * DAYS_PER_YEAR } fn mahadasha_years(lord: DashaLord) -> f64 { match lord { DashaLord::Ketu => 7.0, DashaLord::Venus => 20.0, DashaLord::Sun => 6.0, DashaLord::Moon => 10.0, DashaLord::Mars => 7.0, DashaLord::Rahu => 18.0, DashaLord::Jupiter => 16.0, DashaLord::Saturn => 19.0, DashaLord::Mercury => 17.0, } } ``` -------------------------------- ### POST /calculate_kundli_with_engine Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/calculate/index.html?search= Calculates a complete kundli chart by injecting a custom astronomical engine implementation. ```APIDOC ## POST /calculate_kundli_with_engine ### Description Calculates a complete kundli with an injected astronomical engine, allowing for custom calculation logic. ### Method POST ### Endpoint /calculate_kundli_with_engine ### Parameters #### Request Body - **engine_type** (string) - Required - The identifier for the custom AstroEngine. - **params** (object) - Required - Calculation parameters required by the specific engine. ### Request Example { "engine_type": "custom_ephemeris", "params": { "precision": "high" } } ### Response #### Success Response (200) - **kundli_data** (object) - The calculated astrological chart data. #### Response Example { "status": "success", "data": { "ascendant": "Scorpio", "planets": {} } } ``` -------------------------------- ### Rust: Helper function to create a sample KundliConfig Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/calculate.rs.html?search=std%3A%3Avec This function creates a `KundliConfig` object from an `AstroRequest`. It then configures the object to include D9 (Navamsa) and Dasha (planetary periods) calculations. This is used to set up specific test scenarios. ```rust fn sample_config(request: &AstroRequest) -> KundliConfig { KundliConfig::from_request(request) .with_include_d9(true) .with_include_dasha(true) } ``` -------------------------------- ### From and Into Implementations (Rust) Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.SwissEphConfig.html?search= Illustrates the `From` for `T` and `Into` for `T` blanket implementations. `From` for `T` simply returns the argument, while `Into` relies on `U::from(self)`. ```rust fn from(t: T) -> T ``` ```rust fn into(self) -> U ``` -------------------------------- ### Rust Struct for House Numbers Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/model.rs.html?search=std%3A%3Avec Defines the `HouseNumber` struct, representing a house in astrological charts. It enforces valid values from 1 to 12 using a checked constructor. This struct is used to denote the house a planet occupies or the start of a house cusp. ```rust pub struct HouseNumber(u8); impl HouseNumber { pub const MIN: u8 = 1; pub const MAX: u8 = 12; pub fn new(value: u8) -> Option { (Self::MIN..=Self::MAX) .contains(&value) .then_some(Self(value)) } pub const fn get(self) -> u8 { self.0 } } ``` -------------------------------- ### Initialize and validate AstroRequest Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.AstroRequest.html?search=u32+-%3E+bool Demonstrates the constructor for default settings and the validation method to ensure input parameters are within valid ranges. ```rust let request = AstroRequest::new(jd_ut, lat, lon, bodies); let validated = request.with_zodiac(ZodiacType::Tropical).validate(); ``` -------------------------------- ### HouseNumber Constants and Methods in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.HouseNumber.html?search= Provides constants `MIN` and `MAX` for the smallest and largest valid house numbers, respectively. The `new` function creates a checked `HouseNumber`, returning `None` for invalid values. The `get` method returns the raw `u8` value. ```rust pub const MIN: u8 = 1; pub const MAX: u8 = 12; pub fn new(value: u8) -> Option; pub const fn get(self) -> u8; ``` -------------------------------- ### Initialize and Validate AstroRequest Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.AstroRequest.html?search= Demonstrates how to instantiate an AstroRequest with default settings and validate the structural integrity of the input data. ```rust let request = AstroRequest::new(2451545.0, 28.61, 77.20, vec![AstroBody::Sun]); if let Err(e) = request.validate() { eprintln!("Invalid request: {:?}", e); } ``` -------------------------------- ### Generic Blanket Implementations for Pada in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.Pada.html Demonstrates generic blanket implementations for the Pada struct, including Any, Borrow, BorrowMut, CloneToUninit, From, Into, ToOwned, TryFrom, and TryInto. These implementations leverage Rust's trait system for broad applicability. ```rust impl Any for T where T: 'static + ?Sized impl Borrow for T where T: ?Sized impl BorrowMut for T where T: ?Sized impl CloneToUninit for T where T: Clone impl From for T impl Into for T where U: From impl ToOwned for T where T: Clone impl TryFrom for T where U: Into impl TryInto for T where U: TryFrom ``` -------------------------------- ### Test Nakshatra Progress Ratio Calculation in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search=u32+-%3E+bool Tests the `nakshatra_progress_ratio` function, which calculates the progress within the current Nakshatra as a ratio (0.0 to 1.0). It verifies the ratio at the start (0.0), middle (0.5), and near the end of a Nakshatra. It also tests that the ratio resets correctly when crossing Nakshatra boundaries. ```rust #[test] fn test_nakshatra_progress_ratio_start() { assert!((nakshatra_progress_ratio(0.0).unwrap() - 0.0).abs() < 1e-10); } #[test] fn test_nakshatra_progress_ratio_middle() { let mid_degrees = DEGREES_PER_NAKSHATRA / 2.0; let ratio = nakshatra_progress_ratio(mid_degrees).unwrap(); assert!((ratio - 0.5).abs() < 1e-10); } #[test] fn test_nakshatra_progress_ratio_end() { let end_degrees = DEGREES_PER_NAKSHATRA - 0.001; let ratio = nakshatra_progress_ratio(end_degrees).unwrap(); assert!(ratio < 1.0); assert!(ratio > 0.99); } #[test] fn test_nakshatra_progress_ratio_across_nakshatras() { // Progress ratio should reset at each nakshatra boundary let ratio1 = nakshatra_progress_ratio(13.0).unwrap(); } ``` -------------------------------- ### Initialize and validate AstroRequest Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.AstroRequest.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create a new instance of AstroRequest using default settings and how to validate the structural integrity of the request parameters. ```rust let request = AstroRequest::new(2459000.0, 28.6, 77.2, vec![AstroBody::Sun]); let validated = request.validate(); let custom_request = request .with_zodiac(ZodiacType::Tropical) .with_ayanamsha(Ayanamsha::None); ``` -------------------------------- ### Test Pada Calculation Across Nakshatras in Rust Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/derive/nakshatra.rs.html?search=u32+-%3E+bool Tests the `pada_from_longitude` function to ensure the Pada pattern is consistent across all Nakshatras. It uses small offsets from Nakshatra start points to avoid floating-point boundary issues and verifies that longitudes within each Pada range correctly return the corresponding Pada number (1-4). ```rust #[test] fn test_pada_from_longitude_across_nakshatras() { // Each nakshatra should have the same pada pattern // Use small offsets from nakshatra start to avoid boundary floating-point issues // DEGREES_PER_PADA = 3.333..., so: // Pada 1: 0 - 3.333 // Pada 2: 3.333 - 6.666 // Pada 3: 6.666 - 10.0 // Pada 4: 10.0 - 13.333 for i in 0..27 { let base = DEGREES_PER_NAKSHATRA * (i as f64) + 0.1; // Small offset from boundary assert_eq!(pada_from_longitude(base).unwrap().get(), 1); // 0.1 is in pada 1 assert_eq!(pada_from_longitude(base + 3.5).unwrap().get(), 2); // 3.6 is in pada 2 assert_eq!(pada_from_longitude(base + 7.0).unwrap().get(), 3); // 7.1 is in pada 3 assert_eq!(pada_from_longitude(base + 10.5).unwrap().get(), 4); // 10.6 is in pada 4 } } ``` -------------------------------- ### Calculate Kundli (Default Engine) Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/calculate/index.html?search=std%3A%3Avec Calculates a complete kundli using the default Swiss Ephemeris-backed engine. This is the primary entry point for most users. ```APIDOC ## POST /calculate/kundli ### Description Calculates a complete kundli using the default Swiss Ephemeris-backed engine. ### Method POST ### Endpoint /calculate/kundli ### Parameters #### Request Body - **birth_details** (object) - Required - Details about the birth event (e.g., date, time, location). - **year** (integer) - Required - Birth year. - **month** (integer) - Required - Birth month (1-12). - **day** (integer) - Required - Birth day (1-31). - **hour** (integer) - Required - Birth hour (0-23). - **minute** (integer) - Required - Birth minute (0-59). - **latitude** (float) - Required - Birth latitude. - **longitude** (float) - Required - Birth longitude. - **timezone** (string) - Required - Birth timezone (e.g., "UTC", "Asia/Kolkata"). ### Request Example ```json { "birth_details": { "year": 1990, "month": 5, "day": 15, "hour": 10, "minute": 30, "latitude": 28.6139, "longitude": 77.2090, "timezone": "Asia/Kolkata" } } ``` ### Response #### Success Response (200) - **kundli_data** (object) - The calculated kundli data. - **planets** (object) - Positions of planets. - **houses** (object) - House cusps and significations. - **aspects** (object) - Planetary aspects. - **dashas** (object) - Planetary periods. - **yoga** (object) - Astrological yogas. #### Response Example ```json { "kundli_data": { "planets": { "sun": {"longitude": "15° Aries", "degree": 15.5}, "moon": {"longitude": "20° Taurus", "degree": 20.2} }, "houses": { "ascendant": {"sign": "Leo", "degree": 10.1}, "house_1": {"cusp": "10° Leo", "significator": "Self"} }, "aspects": [ {"planet1": "Sun", "planet2": "Moon", "type": "Trine"} ], "dashas": { "current_dasha": {"planet": "Jupiter", "start_date": "2023-01-01", "end_date": "2029-01-01"} }, "yoga": { "name": "Raja Yoga", "description": "Indicates success and authority." } } } ``` ``` -------------------------------- ### Pada Trait Implementations Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.Pada.html?search=std%3A%3Avec Details on the trait implementations for the Pada struct, including Clone, Debug, PartialEq, Copy, Eq, and others. ```APIDOC ## Trait Implementations for Pada ### `Clone` Allows creating a duplicate of a `Pada` value. ### `Debug` Formats the `Pada` value for debugging purposes. ### `Hash` Enables hashing of `Pada` values, useful for collections like HashMaps. ### `PartialEq` Allows comparison of `Pada` values for equality (`==`) and inequality (`!=`). ### `Copy` Indicates that `Pada` values can be copied implicitly. ### `Eq` A marker trait indicating that equality is reflexive, symmetric, and transitive. ### Auto Trait Implementations * `Freeze` * `RefUnwindSafe` * `Send` * `Sync` * `Unpin` * `UnsafeUnpin` * `UnwindSafe` ### Blanket Implementations * `Any` * `Borrow` * `BorrowMut` * `CloneToUninit` (Nightly-only experimental) * `From` * `Into` * `ToOwned` * `TryFrom` * `TryInto` ``` -------------------------------- ### Pada Implementations Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.Pada.html?search= Details on the trait implementations for the Pada struct. ```APIDOC ## Trait Implementations for Pada ### `Clone` - **clone(&self)** -> Pada Returns a duplicate of the `Pada` value. - **clone_from(&mut self, source: &Self)** Performs copy-assignment from `source`. ### `Debug` - **fmt(&self, f: &mut Formatter<'_>)** -> Result Formats the `Pada` value using the given formatter. ### `Hash` - **hash<__H: Hasher>(&self, state: &mut __H)** Feeds this `Pada` value into the given `Hasher`. - **hash_slice(data: &[Self], state: &mut H)** where H: Hasher, Self: Sized Feeds a slice of `Pada` values into the given `Hasher`. ### `PartialEq` - **eq(&self, other: &Pada)** -> bool Tests for `self` and `other` values to be equal. - **ne(&self, other: &Rhs)** -> bool Tests for inequality (`!=`). ### `Copy` Indicates that `Pada` can be copied implicitly. ### `Eq` Indicates that `Pada` implements total equality. ### `StructuralPartialEq` Indicates structural equality comparison. ### Auto Trait Implementations - `Freeze` - `RefUnwindSafe` - `Send` - `Sync` - `Unpin` - `UnsafeUnpin` - `UnwindSafe` ### Blanket Implementations (Generic) These are implementations provided by the Rust compiler for generic traits when applicable. - `Any` - `Borrow` - `BorrowMut` - `CloneToUninit` (Nightly-only experimental) - `From` - `Into` - `ToOwned` - `TryFrom` - `TryInto` ``` -------------------------------- ### Calculate Kundli using kundli-rs Source: https://docs.rs/kundli-rs/latest/kundli_rs/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the standard workflow for generating a kundli chart. It involves creating an AstroRequest with coordinates and bodies, configuring the output with KundliConfig, and executing the calculation. ```rust use kundli_rs::calculate_kundli; use kundli_rs::kundli::astro::{AstroBody, AstroRequest}; use kundli_rs::kundli::config::KundliConfig; let request = AstroRequest::new( 2451545.0, 37.5665, 126.9780, vec![AstroBody::Sun, AstroBody::Moon, AstroBody::Saturn], ); let config = KundliConfig::from_request(&request) .with_include_d9(true) .with_include_dasha(true); let result = calculate_kundli(request, config)?; println!("Lagna sign: {:?}", result.lagna.sign); ``` -------------------------------- ### Implement PartialEq for PlanetPlacement in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/model/struct.PlanetPlacement.html Provides implementations for the PartialEq trait for the PlanetPlacement struct. This allows for comparing two PlanetPlacement instances for equality, which is essential for verifying data integrity and in testing scenarios. ```rust impl PartialEq for PlanetPlacement fn eq(&self, other: &PlanetPlacement) -> bool fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### calculate_kundli Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/calculate/fn.calculate_kundli.html?search=u32+-%3E+bool Calculates a complete kundli using the default Swiss Ephemeris-backed engine. This is the most convenient entrypoint for consumers who do not need to customize the astronomical backend. It validates the request, checks that request-level settings match the provided KundliConfig, runs the default engine, and assembles the final KundliResult. Optional output sections are controlled by KundliConfig::include_d9 and KundliConfig::include_dasha. ```APIDOC ## POST /calculate_kundli ### Description Calculates a complete kundli using the default Swiss Ephemeris-backed engine. This function is the most convenient entrypoint for consumers who do not need to customize the astronomical backend. It validates the request, checks that request-level settings match the provided `KundliConfig`, runs the default engine, and assembles the final `KundliResult`. Optional output sections are controlled by `KundliConfig::include_d9` and `KundliConfig::include_dasha`. ### Method POST ### Endpoint /calculate_kundli ### Parameters #### Request Body - **request** (AstroRequest) - Required - The astronomical request details. - **config** (KundliConfig) - Required - The configuration for generating the kundli. ### Request Example ```json { "request": { "latitude": 28.6139, "longitude": 77.2090, "year": 2023, "month": 10, "day": 27, "hour": 10, "minute": 30, "timezone": "Asia/Kolkata" }, "config": { "include_d9": true, "include_dasha": true } } ``` ### Response #### Success Response (200) - **KundliResult** - The calculated kundli result. #### Response Example ```json { "result": { "planets": [ { "name": "Sun", "degree": 12.34, "sign": "Libra" }, { "name": "Moon", "degree": 23.45, "sign": "Scorpio" } ], "houses": [ { "sign": "Aries", "degree": 5.67 }, { "sign": "Taurus", "degree": 18.90 } ], "d9_chart": { "planets": [ { "name": "Sun", "degree": 15.67, "sign": "Virgo" } ] }, "dasha_info": { "current_dasha": { "planet": "Jupiter", "start_date": "2020-01-01", "end_date": "2032-01-01" } } } } ``` #### Error Response (400) - **KundliError** - Details about the error encountered during calculation. ``` -------------------------------- ### Rust: Helper function to create a sample AstroRequest Source: https://docs.rs/kundli-rs/latest/src/kundli_rs/kundli/calculate.rs.html?search=std%3A%3Avec This function generates a sample `AstroRequest` object. It initializes the request with specific values for Julian Day, latitude, longitude, and a vector of celestial bodies (Sun, Moon, Saturn). This is useful for setting up test cases. ```rust fn sample_request() -> AstroRequest { AstroRequest::new( 2451545.0, 37.5665, 126.9780, vec![AstroBody::Sun, AstroBody::Moon, AstroBody::Saturn], ) } ``` -------------------------------- ### Implement Display for InputConfigMismatchField in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/error/enum.InputConfigMismatchField.html?search=u32+-%3E+bool Illustrates the implementation of the `Display` trait for `InputConfigMismatchField`. This allows the enum variants to be formatted as user-facing strings, useful for error messages or logs. ```rust impl Display for InputConfigMismatchField { fn fmt(&self, f: &mut Formatter<'_>) -> Result { // Implementation details would go here, likely a match statement // For example: match self { InputConfigMismatchField::Zodiac => write!(f, "Zodiac"), InputConfigMismatchField::Ayanamsha => write!(f, "Ayanamsha"), InputConfigMismatchField::HouseSystem => write!(f, "HouseSystem"), InputConfigMismatchField::NodeType => write!(f, "NodeType"), } } } ``` -------------------------------- ### Implement PartialEq for InputConfigMismatchField in Rust Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/error/enum.InputConfigMismatchField.html?search=u32+-%3E+bool Details the implementation of the `PartialEq` trait for `InputConfigMismatchField`. This enables comparison between enum variants, crucial for checking if two configuration fields are indeed the same or different. ```rust impl PartialEq for InputConfigMismatchField { fn eq(&self, other: &InputConfigMismatchField) -> bool { // Implementation details would go here, likely a match statement // For example: match (self, other) { (InputConfigMismatchField::Zodiac, InputConfigMismatchField::Zodiac) => true, (InputConfigMismatchField::Ayanamsha, InputConfigMismatchField::Ayanamsha) => true, (InputConfigMismatchField::HouseSystem, InputConfigMismatchField::HouseSystem) => true, (InputConfigMismatchField::NodeType, InputConfigMismatchField::NodeType) => true, _ => false, } } fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } ``` -------------------------------- ### Calculate Kundli (Custom Engine) Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/calculate/index.html?search=std%3A%3Avec Calculates a complete kundli with an injected astronomical engine. Use this when you need to provide a custom `AstroEngine` implementation. ```APIDOC ## POST /calculate/kundli/custom ### Description Calculates a complete kundli with an injected astronomical engine. Use this when you need to provide a custom `AstroEngine` implementation. ### Method POST ### Endpoint /calculate/kundli/custom ### Parameters #### Request Body - **birth_details** (object) - Required - Details about the birth event (e.g., date, time, location). - **year** (integer) - Required - Birth year. - **month** (integer) - Required - Birth month (1-12). - **day** (integer) - Required - Birth day (1-31). - **hour** (integer) - Required - Birth hour (0-23). - **minute** (integer) - Required - Birth minute (0-59). - **latitude** (float) - Required - Birth latitude. - **longitude** (float) - Required - Birth longitude. - **timezone** (string) - Required - Birth timezone (e.g., "UTC", "Asia/Kolkata"). - **engine_config** (object) - Optional - Configuration for the custom astronomical engine. - **engine_type** (string) - Required - Type of the custom engine (e.g., "custom_ephemeris", "simulated_engine"). - **engine_parameters** (object) - Optional - Specific parameters for the chosen engine type. ### Request Example ```json { "birth_details": { "year": 1990, "month": 5, "day": 15, "hour": 10, "minute": 30, "latitude": 28.6139, "longitude": 77.2090, "timezone": "Asia/Kolkata" }, "engine_config": { "engine_type": "custom_ephemeris", "engine_parameters": { "ephemeris_path": "/path/to/custom/ephemeris.se1" } } } ``` ### Response #### Success Response (200) - **kundli_data** (object) - The calculated kundli data. - **planets** (object) - Positions of planets. - **houses** (object) - House cusps and significations. - **aspects** (object) - Planetary aspects. - **dashas** (object) - Planetary periods. - **yoga** (object) - Astrological yogas. #### Response Example ```json { "kundli_data": { "planets": { "sun": {"longitude": "15° Aries", "degree": 15.5}, "moon": {"longitude": "20° Taurus", "degree": 20.2} }, "houses": { "ascendant": {"sign": "Leo", "degree": 10.1}, "house_1": {"cusp": "10° Leo", "significator": "Self"} }, "aspects": [ {"planet1": "Sun", "planet2": "Moon", "type": "Trine"} ], "dashas": { "current_dasha": {"planet": "Jupiter", "start_date": "2023-01-01", "end_date": "2029-01-01"} }, "yoga": { "name": "Raja Yoga", "description": "Indicates success and authority." } } } ``` ``` -------------------------------- ### TryFrom Trait Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/config/struct.KundliConfig.html?search=u32+-%3E+bool Documentation for the TryFrom trait, which provides a fallible conversion from one type to another. ```APIDOC ## `impl TryFrom for T` ### Description Provides a fallible conversion from type `U` into type `T`. ### Method `try_from` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let u_value: U = /* ... */; match T::try_from(u_value) { Ok(t_value) => { // Conversion successful } Err(error) => { // Conversion failed } } ``` ### Response #### Success Response (Ok) - **T** (type) - The successfully converted value of type `T`. #### Error Response (Err) - **Error** (type) - The error type associated with the conversion, defined by `>::Error`. #### Response Example ```json { "Ok": "converted_value_of_type_T" } ``` ```json { "Err": "conversion_error_details" } ``` ``` ```APIDOC ## `type Error = >::Error` ### Description The associated error type returned when a conversion using `TryFrom` fails. ### Method N/A (Associated Type) ### Parameters None ### Request Example N/A ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Rust: Implement TryFrom Trait for Fallible Conversions Source: https://docs.rs/kundli-rs/latest/kundli_rs/kundli/astro/struct.AstroRequest.html?search=u32+-%3E+bool Demonstrates the implementation of the `TryFrom` trait in Rust, allowing for fallible conversions from one type to another. This is useful when a conversion might fail and needs to return an error. ```rust impl TryFrom for MyType { type Error = ConversionError; fn try_from(value: u32) -> Result { if value < 100 { Ok(MyType(value)) } else { Err(ConversionError::ValueTooLarge) } } } ```