Skip to content

Commit

Permalink
[NFY] impl FromLua for out types
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 24, 2024
1 parent 65d29fe commit 06da5cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/content.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// SPDX-FileCopyrightText: © 2023 Caleb Maclennan <caleb@alerque.com>
// SPDX-License-Identifier: LGPL-3.0-only

use mlua::prelude::*;

Check failure on line 4 in src/content.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `mlua`

error[E0433]: failed to resolve: use of undeclared crate or module `mlua` --> src/content.rs:4:5 | 4 | use mlua::prelude::*; | ^^^^ use of undeclared crate or module `mlua`

Check failure on line 4 in src/content.rs

View workflow job for this annotation

GitHub Actions / test

failed to resolve: use of undeclared crate or module `mlua`
use mlua::FromLua;

Check failure on line 5 in src/content.rs

View workflow job for this annotation

GitHub Actions / clippy

unresolved import `mlua`

error[E0432]: unresolved import `mlua` --> src/content.rs:5:5 | 5 | use mlua::FromLua; | ^^^^ use of undeclared crate or module `mlua`

Check failure on line 5 in src/content.rs

View workflow job for this annotation

GitHub Actions / test

unresolved import `mlua`

use crate::types::Result;
use regex::Regex;
use std::{borrow::Cow, fmt, fmt::Display, str::FromStr};
Expand All @@ -12,7 +15,7 @@ pub enum Segment {
Word(String),
}

#[derive(Debug, Clone)]
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct Chunk {
pub segments: Vec<Segment>,
Expand Down Expand Up @@ -80,3 +83,18 @@ impl Display for Chunk {
Ok(())
}
}

impl FromLua for Chunk {
fn from_lua(_value: LuaValue, _: &Lua) -> LuaResult<Self> {

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find type `LuaResult` in this scope

error[E0412]: cannot find type `LuaResult` in this scope --> src/content.rs:88:47 | 88 | fn from_lua(_value: LuaValue, _: &Lua) -> LuaResult<Self> { | ^^^^^^^^^ help: a type alias with a similar name exists: `Result` | ::: src/types.rs:13:1 | 13 | pub type Result<T> = anyhow::Result<T>; | --------------------------------------- similarly named type alias `Result` defined here

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find type `Lua` in this scope

error[E0412]: cannot find type `Lua` in this scope --> src/content.rs:88:39 | 88 | fn from_lua(_value: LuaValue, _: &Lua) -> LuaResult<Self> { | ^^^ not found in this scope

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find type `LuaValue` in this scope

error[E0412]: cannot find type `LuaValue` in this scope --> src/content.rs:88:25 | 88 | fn from_lua(_value: LuaValue, _: &Lua) -> LuaResult<Self> { | ^^^^^^^^ not found in this scope

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / test

cannot find type `LuaValue` in this scope

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / test

cannot find type `Lua` in this scope

Check failure on line 88 in src/content.rs

View workflow job for this annotation

GitHub Actions / test

cannot find type `LuaResult` in this scope
Ok(split_chunk("foo bar"))
//match value {
// LuaValue::String(s) => {
// let f = s.to_string_lossy();
// dbg!(f);
// Ok(split_chunk("foo bar"))
// //Ok(s.to_string_lossy().into())
// }
// _ => todo!(),
//}
}
}
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#![doc = include_str!("../README.md")]

use mlua::prelude::*;

Check failure on line 6 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared crate or module `mlua`

error[E0433]: failed to resolve: use of undeclared crate or module `mlua` --> src/lib.rs:6:5 | 6 | use mlua::prelude::*; | ^^^^ use of undeclared crate or module `mlua`

Check failure on line 6 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

failed to resolve: use of undeclared crate or module `mlua`

use regex::Regex;
use titlecase::titlecase as gruber_titlecase;
use unicode_titlecase::tr_az::StrTrAzCasing;
Expand Down Expand Up @@ -45,6 +47,10 @@ pub fn to_case(
}
}

pub fn testf(_chunk: impl Into<Chunk>, s: String) -> Result<String> {
Ok(s.into())
}

/// Convert a string to title case following typesetting conventions for a target locale
pub fn to_titlecase(
chunk: impl Into<Chunk>,
Expand Down
4 changes: 3 additions & 1 deletion src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

use crate::*;
use mlua::prelude::*;
//use mlua::prelude::*;

pub use crate::types::{Case, Locale, Result, StyleGuide};

Expand All @@ -22,6 +22,8 @@ fn decasify(lua: &Lua) -> LuaResult<LuaTable> {
let version = option_env!("VERGEN_GIT_DESCRIBE").unwrap_or_else(|| env!("CARGO_PKG_VERSION"));
let version = lua.create_string(version)?;
exports.set("version", version).unwrap();
//dbg!(testf);
exports.set("testf", LuaFunction::wrap_raw(testf))?;
Ok(exports)
}

Expand Down

0 comments on commit 06da5cd

Please sign in to comment.