d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
834 stars 40 forks source link

Optional values from at function #21

Closed sbeckeriv closed 8 years ago

sbeckeriv commented 8 years ago

Hello,

My question is can hash at return a rust option or can i get a hint of the type from any object. Or match on the type AnyObject can become?

Question really about the Hash but could apply to Array. I am looking for a key that might not be there. Right now hash returns AnyObject. Not sure if its possible but the Option would help a lot! I am currently throwing my results in to a rust HashMap then converting it to a Hash before returning. If I can sort out the nil issue I can just use a Hash from the start.

Thanks! It was fun and easy! I look forward to really using ruru in a real project.

Becker

For reference my code https://github.com/sbeckeriv/greedy-color

sbeckeriv commented 8 years ago

Hello, I read over the ruby-sys code. It looks like the value has is_(type) methods pretty well defined with a ty method that returns the type. Since Hash exposes this I am now check for nil. I think my comment stands. I will try a pull request for what I am thinking.

Thanks Becker