1use crate::{sys, Error, Status};
2use std::convert::TryFrom;
3use std::ffi::CStr;
4
5#[derive(Debug, Clone, Copy)]
6pub struct NodeVersion {
7 pub major: u32,
8 pub minor: u32,
9 pub patch: u32,
10 pub release: &'static str,
11}
12
13impl TryFrom<sys::napi_node_version> for NodeVersion {
14 type Error = Error;
15
16 fn try_from(value: sys::napi_node_version) -> Result<NodeVersion, Error> {
17 Ok(NodeVersion {
18 major: value.major,
19 minor: value.minor,
20 patch: value.patch,
21 release: unsafe {
22 CStr::from_ptr(value.release)
23 .to_str()
24 .map_err(|_| Error::new(Status::StringExpected, reason:"Invalid release name".to_owned()))?
25 },
26 })
27 }
28}
29