From 2b7bb8903798b53fe74f66006129d5cbd45b9cdd Mon Sep 17 00:00:00 2001 From: highflowey Date: Fri, 23 Aug 2024 00:50:05 +0330 Subject: [PATCH] StandardLibrary trait --- crates/lune-std/src/library.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/lune-std/src/library.rs b/crates/lune-std/src/library.rs index 9a301f5..5c856b4 100644 --- a/crates/lune-std/src/library.rs +++ b/crates/lune-std/src/library.rs @@ -2,6 +2,17 @@ use std::str::FromStr; use mlua::prelude::*; +pub trait StandardLibrary +where + Self: Sized + 'static + FromStr, +{ + const ALL: &'static [Self]; + + fn name(&self) -> &'static str; + + fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult>; +} + /** A standard library provided by Lune. */ @@ -20,12 +31,12 @@ pub enum LuneStandardLibrary { #[cfg(feature = "roblox")] Roblox, } -impl LuneStandardLibrary { +impl StandardLibrary for LuneStandardLibrary { /** All available standard libraries. */ #[rustfmt::skip] - pub const ALL: &'static [Self] = &[ + const ALL: &'static [Self] = &[ #[cfg(feature = "datetime")] Self::DateTime, #[cfg(feature = "fs")] Self::Fs, #[cfg(feature = "luau")] Self::Luau, @@ -44,7 +55,7 @@ impl LuneStandardLibrary { #[must_use] #[rustfmt::skip] #[allow(unreachable_patterns)] - pub fn name(&self) -> &'static str { + fn name(&self) -> &'static str { match self { #[cfg(feature = "datetime")] Self::DateTime => "datetime", #[cfg(feature = "fs")] Self::Fs => "fs", @@ -70,7 +81,7 @@ impl LuneStandardLibrary { */ #[rustfmt::skip] #[allow(unreachable_patterns)] - pub fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult> { + fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult> { let res: LuaResult = match self { #[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::module(lua), #[cfg(feature = "fs")] Self::Fs => lune_std_fs::module(lua),