mirror of
https://github.com/noib3/nvim-oxi.git
synced 2025-08-04 19:08:31 +00:00
feat: implement TryFrom<Object>
for NvimString
This commit is contained in:
parent
75e4b36478
commit
e9bb99794a
2 changed files with 16 additions and 15 deletions
|
@ -113,19 +113,6 @@ impl FromObject for Float {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromObject for crate::String {
|
||||
fn from_object(obj: Object) -> Result<Self, Error> {
|
||||
match obj.kind() {
|
||||
ObjectKind::String => Ok(unsafe { obj.into_string_unchecked() }),
|
||||
|
||||
other => Err(Error::FromWrongType {
|
||||
expected: "string",
|
||||
actual: other.as_static(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromObject for Array {
|
||||
fn from_object(obj: Object) -> Result<Self, Error> {
|
||||
match obj.kind() {
|
||||
|
|
|
@ -8,8 +8,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use luajit as lua;
|
||||
|
||||
use crate::NvimStr;
|
||||
use crate::StringBuilder;
|
||||
use crate::{conversion, NvimStr, Object, ObjectKind, StringBuilder};
|
||||
|
||||
/// Binding to the string type used by Neovim.
|
||||
///
|
||||
|
@ -234,6 +233,21 @@ impl PartialEq<std::string::String> for String {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Object> for String {
|
||||
type Error = conversion::Error;
|
||||
|
||||
#[inline]
|
||||
fn try_from(obj: crate::Object) -> Result<Self, Self::Error> {
|
||||
match obj.kind() {
|
||||
ObjectKind::String => Ok(unsafe { obj.into_string_unchecked() }),
|
||||
other => Err(conversion::Error::FromWrongType {
|
||||
expected: "string",
|
||||
actual: other.as_static(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl lua::Pushable for String {
|
||||
#[inline]
|
||||
unsafe fn push(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue