From a6562a7260596717513dcdc65d4de5e9ec516b1f Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Wed, 31 Jan 2018 19:06:54 +0300 Subject: [PATCH] Document RuntimeArgs. --- src/host.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/host.rs b/src/host.rs index 948de64..200da0f 100644 --- a/src/host.rs +++ b/src/host.rs @@ -13,12 +13,20 @@ impl<'a> From<&'a [RuntimeValue]> for RuntimeArgs<'a> { } impl<'a> RuntimeArgs<'a> { - /// Extract argument by index `idx` returning error if cast is invalid or not enough arguments + /// Extract argument by index `idx`. + /// + /// # Errors + /// + /// Returns `Err` if cast is invalid or not enough arguments. pub fn nth_checked(&self, idx: usize) -> Result where RuntimeValue: TryInto { Ok(self.nth_value_checked(idx)?.try_into().map_err(|_| Error::Value("Invalid argument cast".to_owned()))?) } - /// Extract argument as a runtime value by index `idx` returning error is not enough arguments + /// Extract argument as a [`RuntimeValue`] by index `idx`. + /// + /// # Errors + /// + /// Returns `Err` if this list have not enough arguments. pub fn nth_value_checked(&self, idx: usize) -> Result { if self.0.len() <= idx { return Err(Error::Value("Invalid argument index".to_owned())); @@ -26,6 +34,11 @@ impl<'a> RuntimeArgs<'a> { Ok(self.0[idx]) } + /// Extract argument by index `idx`. + /// + /// # Panics + /// + /// Panics if cast is invalid or not enough arguments. pub fn nth(&self, idx: usize) -> T where RuntimeValue: TryInto { let value = self.nth_value_checked(idx).expect("Invalid argument index"); value.try_into().expect("Unexpected argument type")