Compare commits

...

7 Commits

Author SHA1 Message Date
3b0243e597 fix(deps): update rust crate rlua to 0.20.0 2024-04-06 20:35:35 +00:00
2585e7ce34 Merge pull request 'Configure Renovate' (#1) from renovate/configure into master
Reviewed-on: https://git.front.kjuulh.io/kjuulh/rlua-searcher/pulls/1
2024-04-06 20:07:01 +00:00
158f4c7cb3 Add renovate.json 2023-08-02 10:59:51 +00:00
9073e924c6 feat: with publisable
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-02 12:48:38 +02:00
22672c76b0 docs: update readme
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-02 12:47:36 +02:00
ae42899727 feat: with iocat
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-08-02 12:45:56 +02:00
2b29a9d0e8 feat: update to rlua 19.5
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-07-02 11:29:04 +02:00
7 changed files with 112 additions and 10 deletions

View File

@@ -2,17 +2,14 @@
name = "rlua-searcher"
version = "0.1.0"
edition = "2021"
authors = ["Andy Weidenbaum <atweiden@ioiojo.com>"]
authors = ["Andy Weidenbaum <atweiden@ioiojo.com>", "Kasper J. Hermansen <contact@kjuulh.io>"]
license = "MIT OR Apache-2.0"
keywords = ["lua"]
homepage = "https://git.sr.ht/~ioiojo/rlua-searcher"
repository = "https://git.sr.ht/~ioiojo/rlua-searcher"
homepage = "https://git.front.kjuulh.io/kjuulh/rlua-searcher"
repository = "https://git.front.kjuulh.io/kjuulh/rlua-searcher"
readme = "README.md"
description = "Require Lua modules by name"
publishable = true
[dependencies]
rlua = "0.18"
[dependencies.io-cat]
git = "https://git.sr.ht/~ioiojo/io-cat"
rev = "74167240f6a284505a1f0a334432352878a7ba99"
rlua = "0.20.0"

View File

@@ -2,6 +2,8 @@
`require` Lua modules by name
(This is a fork of https://git.sr.ht/~ioiojo/rlua-searcher, I don't maintain this code, I just need to available on crates.io for other dependent packages.)
## Description
Encode a Lua module as a `HashMap` of Lua strings indexed by module

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

100
src/io_cat.rs Normal file
View File

@@ -0,0 +1,100 @@
use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::File;
use std::io;
use std::io::{BufReader, Cursor, Read};
use std::path::{Path, PathBuf};
use std::string::String;
pub type CatBox = Box<dyn Cat + Send + Sync>;
pub type CatMap<K> = HashMap<K, CatBox>;
pub trait Cat {
fn cat(&self) -> io::Result<String>;
}
impl Cat for PathBuf {
fn cat(&self) -> io::Result<String> {
self.as_path().cat()
}
}
impl Cat for &Path {
fn cat(&self) -> io::Result<String> {
let mut input = File::open(self)?;
read_to_string(&mut input)
}
}
impl Cat for Cow<'_, Path> {
fn cat(&self) -> io::Result<String> {
self.as_ref().cat()
}
}
impl Cat for String {
fn cat(&self) -> io::Result<String> {
self.as_str().cat()
}
}
impl Cat for &str {
fn cat(&self) -> io::Result<String> {
let mut input = Cursor::new(self);
read_to_string(&mut input)
}
}
impl Cat for Cow<'_, str> {
fn cat(&self) -> io::Result<String> {
self.as_ref().cat()
}
}
fn read_to_string<R>(input: &mut R) -> io::Result<String>
where
R: Read,
{
let mut text = String::new();
let mut reader = BufReader::new(input);
reader.read_to_string(&mut text)?;
Ok(text)
}
#[cfg(test)]
mod tests {
use std::borrow::Cow;
use std::env;
use std::path::Path;
use super::CatMap;
#[test]
fn it_works() {
const ENV_VAR_OS_CARGO_MANIFEST_DIR: &str =
"Unexpectedly could not read `CARGO_MANIFEST_DIR` environment variable";
let mut cat_map: CatMap<Cow<'static, str>> = CatMap::new();
cat_map.insert(Cow::from("Apr"), Box::new("Showers"));
cat_map.insert(
Cow::from("May"),
Box::new(
Path::new(&env::var_os("CARGO_MANIFEST_DIR").expect(ENV_VAR_OS_CARGO_MANIFEST_DIR))
.join("testdata")
.join("may.txt"),
),
);
assert_eq!(
cat_map.get(&Cow::from("Apr")).unwrap().cat().unwrap(),
String::from("Showers")
);
assert_eq!(
cat_map
.get(&Cow::from("May"))
.unwrap()
.cat()
.unwrap()
.trim_end(),
String::from("Flowers")
);
}
}

View File

@@ -1,4 +1,5 @@
mod error;
mod io_cat;
mod searcher;
mod types;

View File

@@ -3,5 +3,5 @@ use std::result;
use crate::error::Error;
pub(crate) type CatMap = io_cat::CatMap<Cow<'static, str>>;
pub(crate) type CatMap = crate::io_cat::CatMap<Cow<'static, str>>;
pub type Result<A> = result::Result<A, Error>;

View File

@@ -1,4 +1,3 @@
use io_cat::CatMap;
use rlua::{Context, Function, Lua, Table, UserData, UserDataMethods, Value};
use rlua_searcher::{AddSearcher, Result};
use std::borrow::Cow;