bitmex-rs icon indicating copy to clipboard operation
bitmex-rs copied to clipboard

How to access values of NewType pattern response structs

Open algoeng opened this issue 4 years ago • 3 comments

The following response structs use the NewType pattern, and member .0 is private. There are no tests/examples on consuming the value of these. How do we access .0 member?

PostOrderCancelAllAfterResponse GetSchemaResponse GetSchemaWebsocketHelpResponse GetUserExecutionHistoryResponse GetUserMinWithdrawalFeeResponse

algoeng avatar Jan 24 '21 06:01 algoeng

Hi @kr011 , thanks for the bug report. I'm working on a fix for this, however, it requires I modify the code generator since these definitions/models are directly generated from the swagger.json.

For now I think you can use std::mem::transmute to get the inner value. e.g.

let resp: PostOrderCancelAllAfterResponse = ...;
let inner: serde_json::Value = unsafe {std::mem::transmute(resp)};

dovahcrow avatar Jan 24 '21 08:01 dovahcrow

Thank you for the quick response. That works for now. Feel free to close this, or keep it if you want to track fixing the code generator.

algoeng avatar Jan 24 '21 08:01 algoeng

I'll keep this until the issue is fixed.

dovahcrow avatar Jan 24 '21 08:01 dovahcrow