Skip to content

Commit

Permalink
fixup! fixup! [NFY] Wrap semver::Version as Lua type
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Oct 10, 2024
1 parent 9bf56fa commit 491753c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 2 additions & 4 deletions rusile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use mlua::prelude::*;
fn rusile(lua: &Lua) -> LuaResult<LuaTable> {
let exports = lua.create_table().unwrap();
exports.set("demo", LuaFunction::wrap_raw(sile::rusile_demo))?;
//exports.set(
// "semver",
// LuaFunction::wrap_raw(sile::types::semver::Semver::new),
//)?;
//dbg!(sile::types::semver::new);
//exports.set("semver", LuaFunction::wrap_raw(sile::types::semver::new))?;
Ok(exports)
}
22 changes: 16 additions & 6 deletions src/types/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@ use semver::Version;
use std::ops::Deref;

pub struct Semver {
pub version: Version,
pub version: Option<Version>,
}

impl Semver {
pub fn new(version: &str) -> crate::Result<Self> {
let version = Version::parse(version)?;
Ok(Semver { version })
pub fn new(version: Option<&str>) -> crate::Result<Self> {
let version = match version {
Some(str) => Self {
version: Some(Version::parse(str)?),
},
None => Self { version: None },
};
Ok(version)
}
}

//pub fn new(version: &str) -> crate::Result<Semver> {
// let version = Version::parse(version)?;
// Ok(Semver { version })
//}

impl Deref for Semver {
type Target = Version;
fn deref(&self) -> &Version {
type Target = Option<Version>;
fn deref(&self) -> &Option<Version> {
&self.version
}
}
Expand Down

0 comments on commit 491753c

Please sign in to comment.