Skip to content

Commit

Permalink
Remove api::v2::assets::ListReqInit
Browse files Browse the repository at this point in the history
Similar to what we did earlier to api::v2::order::ChangeReqInit, this
change removes the api::v2::assets::ListReqInit and makes the ListReq
types default-constructible instead.
  • Loading branch information
d-e-s-o committed Jul 9, 2024
1 parent fbefa5a commit 2d51348
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
`NotPermitted`
- This variant is now used to signal a multitude of conditions,
including certain order submission issues
- Removed `api::v2::order::ChangeReqInit` type in favor of `Default`
impl for `ChangeReq`
- Removed `api::v2::{order::ChangeReqInit,assets::ListReqInit}` types in
favor of `Default` impl for corresponding request types
- Added `name` attribute to `api::v2::watchlist::Watchlist` type
- Added support for updating a watchlist
- Bumped minimum supported Rust version to `1.63`
Expand Down
37 changes: 6 additions & 31 deletions src/api/v2/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,8 @@ use crate::api::v2::asset::Status;
use crate::Str;


/// A helper for initializing `ListReq` objects.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct ListReqInit {
/// See `ListReq::status`.
pub status: Status,
/// See `ListReq::class`.
pub class: Class,
#[doc(hidden)]
pub _non_exhaustive: (),
}

impl ListReqInit {
/// Create an `ListReq` from an `ListReqInit`.
#[inline]
pub fn init(self) -> ListReq {
ListReq {
status: self.status,
class: self.class,
}
}
}


/// A GET request to be made to the /v2/assets endpoint.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct ListReq {
/// The status of assets to include in the response.
#[serde(rename = "status")]
Expand Down Expand Up @@ -83,12 +60,11 @@ mod tests {
/// Check that we can serialize and deserialize a [`ListReq`].
#[test]
fn serialize_deserialize_list_request() {
let request = ListReqInit {
let request = ListReq {
status: Status::Active,
class: Class::UsEquity,
..Default::default()
}
.init();
};

let json = to_json(&request).unwrap();
assert_eq!(from_json::<ListReq>(&json).unwrap(), request);
Expand All @@ -100,7 +76,7 @@ mod tests {
async fn list_us_stock_assets() {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
let request = ListReqInit::default().init();
let request = ListReq::default();
let assets = client.issue::<List>(&request).await.unwrap();

let asset = assets.iter().find(|x| x.symbol == "AAPL").unwrap();
Expand All @@ -115,11 +91,10 @@ mod tests {
async fn list_crypto_assets() {
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
let request = ListReqInit {
let request = ListReq {
class: Class::Crypto,
..Default::default()
}
.init();
};

let assets = client.issue::<List>(&request).await.unwrap();

Expand Down

0 comments on commit 2d51348

Please sign in to comment.