From 09dc89895a13a5eb515d775cae0cc5b8b8779f23 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 25 Jul 2017 00:42:59 +0200 Subject: [PATCH] Add an example --- src/lua.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lua.rs b/src/lua.rs index faadf36..4a5aa19 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -195,6 +195,21 @@ impl<'lua> String<'lua> { /// /// The returned slice will not contain the terminating null byte, but will contain any null /// bytes embedded into the Lua string. + /// + /// # Examples + /// + /// ``` + /// # extern crate rlua; + /// # use rlua::{Lua, String}; + /// # fn main() { + /// let lua = Lua::new(); + /// let globals = lua.globals(); + /// + /// let non_utf8: String = lua.eval(r#" "test\xff" "#, None).unwrap(); + /// assert!(non_utf8.to_str().is_err()); // oh no :( + /// assert_eq!(non_utf8.as_bytes(), &b"test\xff"[..]); + /// # } + /// ``` pub fn as_bytes(&self) -> &[u8] { let lua = self.0.lua; unsafe {