NameGender Rust
[]
= "0.2"
= { = "1", = ["macros", "rt-multi-thread"] }
use ;
async
An async client built on reqwest with rustls; no OpenSSL needed. Get an API
key from the namegender.com dashboard and keep it on
the server.
Lookups
use ;
client.name.await?;
client.email.await?;
client.username.await?;
// Up to 100 values per request, results in the same order
let bulk = client.bulk.await?;
for r in &bulk.results
Every value costs one credit, unknown results included. gender is None
when the API does not know; check probability and sample_size before
trusting an answer.
Options
| Field | Meaning |
|---|---|
country |
Two-letter country code. Andrea is male in Italy and female in Germany. |
locale |
Language tag such as it-IT; its region is the country when country is absent. en sets none. |
ip |
End user IP address; its country is used when neither of the above applies. Not stored. |
best_guess |
Return the more likely gender even when the evidence is weak. |
ai_fallback |
Ask a language model when the dataset has no answer. Requires AI lookups to be enabled on the account. |
country_source on a response says which one set the country: "country",
"locale", "ip" or None.
Errors
A non-2xx response becomes Error::Api with the HTTP status and the API's
reason code. Branch on the code, not the message:
match client.name.await
Salutation
The opening line of a letter or email, in the recipient's language. One credit per name.
use SalutationOptions;
let de = SalutationOptions ;
let r = client.salutation.await?;
println!; // Sehr geehrte Frau Dr. Müller,
let tr = SalutationOptions ;
let r = client.salutation.await?;
println!; // Sayın Ahmet Bey,
// First and last name stored separately; they are not parsed
let r = client.salutation_by_parts.await?;
// Up to 100 names, results in the same order
let bulk = client.salutation_bulk.await?;
println!;
SalutationOptions has language, country, locale, ip, gender
(male, female or neutral; overrides the lookup), min_probability
(50-100, default 90) and title (Dr.). When the gender is not certain the
salutation uses the neutral form: form (gendered, neutral,
organization) and reason say why. salutation.neutral is always the
gender-free line and parts holds the pieces of the formal one. best_guess
does not apply here. An unsupported language is an Error::Api with
invalid_input and HTTP 422.
Country distribution and account
let dist = client.countries.await?;
println!;
let account = client.account.await?; // costs nothing
println!;
countries reports which countries a name is recorded in. It is not a
country-of-origin or ethnicity inference: registrations is counted volume
from the countries that publish counted birth statistics, and attested_in is
presence with no weight attached. Show basis["note"] next to any percentage.
License
MIT