use crate::uuid;
use js::class::Trace;
#[derive(Clone, Trace)]
#[js::class]
pub struct Uuid {
#[qjs(skip_trace)]
pub(crate) value: Option<uuid::Uuid>,
}
#[js::methods]
impl Uuid {
#[qjs(constructor)]
pub fn new(value: String) -> Self {
Self {
value: uuid::Uuid::try_from(value).ok(),
}
}
#[qjs(get)]
pub fn value(&self) -> String {
match &self.value {
Some(v) => v.to_raw(),
None => String::from("Invalid Uuid"),
}
}
pub fn is(a: &Uuid, b: &Uuid) -> bool {
a.value.is_some() && b.value.is_some() && a.value == b.value
}
#[qjs(rename = "toString")]
pub fn js_to_string(&self) -> String {
match &self.value {
Some(v) => v.to_raw(),
None => String::from("Invalid Uuid"),
}
}
#[qjs(rename = "toJSON")]
pub fn to_json(&self) -> String {
match &self.value {
Some(v) => v.to_raw(),
None => String::from("Invalid Uuid"),
}
}
}