pub struct CensusClient { /* private fields */ }Expand description
Client for US Census Bureau API
Provides access to:
- Decennial Census data
- American Community Survey (ACS)
- Economic indicators
- Population estimates
§Example
ⓘ
use ruvector_data_framework::CensusClient;
let client = CensusClient::new(None);
let population = client.get_population(2020, "state:*").await?;
let acs_data = client.get_acs5(2021, vec!["B01001_001E"], "county:*").await?;
let datasets = client.get_available_datasets().await?;Implementations§
Source§impl CensusClient
impl CensusClient
Sourcepub fn new(api_key: Option<String>) -> Self
pub fn new(api_key: Option<String>) -> Self
Create a new Census Bureau client
§Arguments
api_key- Optional Census API key (500 req/day without key, unlimited with key) Get key at: https://api.census.gov/data/key_signup.html
Sourcepub fn with_config(
api_key: Option<String>,
embedding_dim: usize,
use_mock: bool,
) -> Self
pub fn with_config( api_key: Option<String>, embedding_dim: usize, use_mock: bool, ) -> Self
Create a new Census client with custom configuration
§Arguments
api_key- Optional Census API keyembedding_dim- Dimension for embeddingsuse_mock- Use mock data when API is unavailable
Sourcepub async fn get_population(
&self,
year: u32,
geography: &str,
) -> Result<Vec<SemanticVector>>
pub async fn get_population( &self, year: u32, geography: &str, ) -> Result<Vec<SemanticVector>>
Get population data for a specific year and geography
§Arguments
year- Census year (e.g., 2020, 2010)geography- Geography filter (e.g., “state:*”, “county:06”, “us:1”)
§Example
ⓘ
// Get all states population
let pop = client.get_population(2020, "state:*").await?;
// Get California counties
let ca_counties = client.get_population(2020, "county:*&in=state:06").await?;Sourcepub async fn get_acs5(
&self,
year: u32,
variables: Vec<&str>,
geography: &str,
) -> Result<Vec<SemanticVector>>
pub async fn get_acs5( &self, year: u32, variables: Vec<&str>, geography: &str, ) -> Result<Vec<SemanticVector>>
Get American Community Survey 5-year estimates
§Arguments
year- Survey year (2009-2021+)variables- Variable codes (e.g., [“B01001_001E”] for total population)geography- Geography filter
§Example
ⓘ
// Get median household income for all states
let income = client.get_acs5(
2021,
vec!["B19013_001E"],
"state:*"
).await?;Sourcepub async fn get_available_datasets(&self) -> Result<Vec<SemanticVector>>
pub async fn get_available_datasets(&self) -> Result<Vec<SemanticVector>>
Sourcepub async fn search_variables(
&self,
dataset: &str,
query: &str,
) -> Result<Vec<SemanticVector>>
pub async fn search_variables( &self, dataset: &str, query: &str, ) -> Result<Vec<SemanticVector>>
Auto Trait Implementations§
impl Freeze for CensusClient
impl !RefUnwindSafe for CensusClient
impl Send for CensusClient
impl Sync for CensusClient
impl Unpin for CensusClient
impl !UnwindSafe for CensusClient
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
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more