# Lightweight queries (/en/docs/rust/query)

The Chinese zodiac animal, zodiac sign and Soul palace major stars, without charting the whole thing.



Some questions do not need a whole chart. These five functions each run only as far as necessary and
return; their results always agree with the corresponding fields of a full chart, because they go
through the same core logic.

<Callout type="info">
  The examples on this page all chart with `Language::EnUS`, so the display values in the output are
  iztro's en-US vocabulary.
</Callout>

***

## get\_zodiac\_by\_solar\_date [#get_zodiac_by_solar_date]

**Purpose** Get the Chinese zodiac animal from a solar date.

**Zi Wei meaning** The zodiac animal is determined by the **year branch**, and when the year branch
turns over is governed by `year_divide`.
For someone born between lunar New Year and the Beginning of Spring, the two settings give different
animals — not a bug, a difference of school.

**Signature**

```rust
pub fn get_zodiac_by_solar_date(
    solar_date: &str,
    language: Language,
    config: Config,
) -> Result<String, IztroError>
```

**Parameters**

| Parameter    | Type       | Required | Default | Description                           |
| ------------ | ---------- | -------- | ------- | ------------------------------------- |
| `solar_date` | `&str`     | Yes      | —       | Solar date in `YYYY-M-D`              |
| `language`   | `Language` | Yes      | —       | Output language                       |
| `config`     | `Config`   | Yes      | —       | Only `year_divide` affects the result |

**Return value** `String` — the animal name translated into the language.

**Example**

```rust
println!("{}", get_zodiac_by_solar_date("2000-8-16", Language::EnUS, Config::default())?);
```

**Output**

```text
dragon
```

**Edge cases and pitfalls**

<Callout type="warn" title="The year boundary moves with the configuration">
  By default the year turns over at lunar New Year. Switch to `YearDivide::Exact` and it turns over at
  the Beginning of Spring, so people born from late January to early February can get a different
  animal.
</Callout>

***

## get\_sign\_by\_solar\_date / get\_sign\_by\_lunar\_date [#get_sign_by_solar_date--get_sign_by_lunar_date]

**Purpose** Get the zodiac sign.

**Zi Wei meaning** The zodiac sign is a Western astrology concept determined solely by the solar
date, unrelated to the Zi Wei algorithm. The lunar version converts to solar first, so both give the
same result for the same day.

**Signature**

```rust
pub fn get_sign_by_solar_date(solar_date: &str, language: Language) -> Result<String, IztroError>
pub fn get_sign_by_lunar_date(
    lunar_date: &str,
    is_leap_month: bool,
    language: Language,
) -> Result<String, IztroError>
```

**Parameters**

| Parameter                   | Type       | Required | Default | Description                                            |
| --------------------------- | ---------- | -------- | ------- | ------------------------------------------------------ |
| `solar_date` / `lunar_date` | `&str`     | Yes      | —       | The date in `YYYY-M-D`                                 |
| `is_leap_month`             | `bool`     | Yes      | —       | Lunar version only: whether that month is a leap month |
| `language`                  | `Language` | Yes      | —       | Output language                                        |

There is no `config` parameter — zodiac signs are unaffected by any setting.

**Return value** `String`.

**Example**

```rust
println!("{}", get_sign_by_solar_date("2000-8-16", Language::EnUS)?);
println!("{}", get_sign_by_lunar_date("2000-7-17", false, Language::EnUS)?);
```

**Output**

```text
leo
leo
```

***

## get\_major\_star\_by\_solar\_date / get\_major\_star\_by\_lunar\_date [#get_major_star_by_solar_date--get_major_star_by_lunar_date]

**Purpose** Get just the Soul palace's major stars, without charting the whole thing.

**Zi Wei meaning** The major stars of the Soul palace are the single most commonly asked item in Zi
Wei Dou Shu. When the Soul palace is empty, convention borrows the major stars of the opposite palace,
and this function already handles that step.

**Signature**

```rust
pub fn get_major_star_by_solar_date(
    solar_date: &str,
    time_index: u8,
    fix_leap: bool,
    language: Language,
    config: Config,
) -> Result<String, IztroError>

pub fn get_major_star_by_lunar_date(
    lunar_date: &str,
    time_index: u8,
    leap: LeapMonth,
    language: Language,
    config: Config,
) -> Result<String, IztroError>
```

**Parameters**

| Parameter                   | Type        | Required | Default | Description                                                                                                  |
| --------------------------- | ----------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `solar_date` / `lunar_date` | `&str`      | Yes      | —       | The date                                                                                                     |
| `time_index`                | `u8`        | Yes      | —       | Hour index 0–12; the Soul palace is fixed jointly by month and hour                                          |
| `fix_leap`                  | `bool`      | Yes      | —       | Solar version only: whether a solar date falling after the 15th of a leap month is treated as the next month |
| `leap`                      | `LeapMonth` | Yes      | —       | Lunar version only: `NotLeap` / `Leap` / `LeapFixed`, see [`by_lunar`](/en/docs/rust/astro#by_lunar)         |
| `language`                  | `Language`  | Yes      | —       | Output language                                                                                              |
| `config`                    | `Config`    | Yes      | —       | Charting configuration                                                                                       |

**Return value** `String` — several major stars separated by commas; the opposite palace's major
stars when the Soul palace is empty.

<Callout type="info">
  Rust names these two functions in the singular, matching iztro, even though the Soul palace can hold
  more than one major star. The plural `get_major_stars` on
  [Star placement](/en/docs/rust/star#get_major_stars--get_minor_stars--get_adjective_stars) is a
  different function: it returns the distribution across all twelve palaces.
</Callout>

**Example**

```rust
let cfg = Config::default();

println!("{}", get_major_star_by_solar_date("2000-8-16", 2, true, Language::EnUS, cfg.clone())?);
println!("{}", get_major_star_by_solar_date("2000-8-16", 2, true, Language::ZhCN, cfg.clone())?);
```

**Output**

```text
emperor
紫微
```

**Edge cases and pitfalls**

<Accordions>
  <Accordion title="Without an hour there is no Soul palace">
    The Soul palace is located jointly from the lunar month and the birth hour, so `time_index` is
    required. Knowing only the date and not the hour, Zi Wei Dou Shu cannot fix a Soul palace.
  </Accordion>

  <Accordion title="For predicates, use the key form">
    The return value is a translated string that changes with the language. For programmatic checks use
    `major_star_keys_of_soul_palace` below, or chart the whole thing and compare the `key` of the
    `major_stars`.
  </Accordion>
</Accordions>

***

## major\_star\_keys\_of\_soul\_palace [#major_star_keys_of_soul_palace]

**Purpose** The Soul palace's major stars as language-independent keys — the key form of the two
functions above, for programmatic checks.

**Signature**

```rust
pub fn major_star_keys_of_soul_palace(astrolabe: &Astrolabe) -> Vec<String>
```

Takes an already-cast chart (pair it with `by_solar` / `by_lunar`); the borrowing rule shares one
implementation with the translated form: an empty Soul palace borrows its opposite's major stars,
and an empty list comes back when the opposite has none either. Keys are independent of the chart
language.

**Example**

```rust
let chart = by_solar("2000-8-16", 2, Gender::Female, true, Language::EnUS, Config::default())?;

println!("{:?}", major_star_keys_of_soul_palace(&chart));
```

**Output**

```text
["ziweiMaj"]
```
