Module: HnApi
- Defined in:
- lib/hn_api.rb
Defined Under Namespace
Classes: HnClient, InternalError, RustBuffer, Story, User
Class Method Summary
collapse
Class Method Details
.rust_call(fn_name, *args) ⇒ Object
618
619
620
621
|
# File 'lib/hn_api.rb', line 618
def self.rust_call(fn_name, *args)
rust_call_with_error(nil, fn_name, *args)
end
|
.rust_call_with_error(error_module, fn_name, *args) ⇒ Object
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
|
# File 'lib/hn_api.rb', line 623
def self.rust_call_with_error(error_module, fn_name, *args)
status = RustCallStatus.new
args << status
result = UniFFILib.public_send(fn_name, *args)
case status.code
when CALL_SUCCESS
result
when CALL_ERROR
if error_module.nil?
status.error_buf.free
raise InternalError, "CALL_ERROR with no error_module set"
else
raise consume_buffer_into_error(error_module, status.error_buf)
end
when CALL_PANIC
if status.error_buf.len > 0
raise InternalError, status.error_buf.consumeIntoString()
else
raise InternalError, "Rust panic"
end
else
raise InternalError, "Unknown call status: #{status.code}"
end
end
|