Skip to content

Commit

Permalink
feat: add needed is methods
Browse files Browse the repository at this point in the history
  • Loading branch information
LeuisKen committed Dec 21, 2024
1 parent af797fd commit 3154021
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bridge/rusty_webf_sys/src/native_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ impl NativeValue {
value
}

pub fn is_string(&self) -> bool {
self.tag == NativeTag::TagString as i32
}

pub fn to_string(&self) -> String {
let ptr = unsafe {
self.u.ptr as *mut SharedNativeString
Expand Down Expand Up @@ -131,6 +135,10 @@ impl NativeValue {
value
}

pub fn is_float64(&self) -> bool {
self.tag == NativeTag::TagFloat64 as i32
}

pub fn to_float64(&self) -> f64 {
unsafe {
self.u.float64
Expand All @@ -145,6 +153,10 @@ impl NativeValue {
value
}

pub fn is_bool(&self) -> bool {
self.tag == NativeTag::TagBool as i32
}

pub fn to_bool(&self) -> bool {
unsafe {
self.u.int64 != 0
Expand All @@ -159,6 +171,10 @@ impl NativeValue {
value
}

pub fn is_int64(&self) -> bool {
self.tag == NativeTag::TagInt as i32
}

pub fn to_int64(&self) -> i64 {
unsafe {
self.u.int64
Expand Down Expand Up @@ -190,6 +206,10 @@ impl NativeValue {
value
}

pub fn is_list(&self) -> bool {
self.tag == NativeTag::TagList as i32
}

pub fn to_list(&self) -> Vec<NativeValue> {
let mut values = Vec::new();
let ptr = unsafe {
Expand Down

0 comments on commit 3154021

Please sign in to comment.